templates: Remove base_path argument from api_arguments_table_generator.

Removes `base_path` argument when making the markdown extension for
parameters in documentation for API endpoints.

This seems to have been originally included for API parameters that
were documented in JSON files, which is no longer in use. Now all
API endpoints in the documentation are documented in
`zerver/openapi/zulip.yaml`.
This commit is contained in:
Lauryn Menard
2023-01-31 19:49:06 +01:00
committed by Tim Abbott
parent f38d5a6a26
commit b64d8e8a52
2 changed files with 13 additions and 41 deletions

View File

@@ -1,5 +1,4 @@
import json import json
import os
import re import re
from typing import Any, Dict, List, Mapping, Sequence from typing import Any, Dict, List, Mapping, Sequence
@@ -50,16 +49,6 @@ OBJECT_CODE_TEMPLATE = "<code>{value}</code>".strip()
class MarkdownArgumentsTableGenerator(Extension): class MarkdownArgumentsTableGenerator(Extension):
def __init__(self, configs: Mapping[str, Any] = {}) -> None:
self.config = {
"base_path": [
".",
"Default location from which to evaluate relative paths for the JSON files.",
],
}
for key, value in configs.items():
self.setConfig(key, value)
def extendMarkdown(self, md: markdown.Markdown) -> None: def extendMarkdown(self, md: markdown.Markdown) -> None:
md.preprocessors.register( md.preprocessors.register(
APIArgumentsTablePreprocessor(md, self.getConfigs()), APIArgumentsTablePreprocessor(md, self.getConfigs()),
@@ -71,7 +60,6 @@ class MarkdownArgumentsTableGenerator(Extension):
class APIArgumentsTablePreprocessor(Preprocessor): class APIArgumentsTablePreprocessor(Preprocessor):
def __init__(self, md: markdown.Markdown, config: Mapping[str, Any]) -> None: def __init__(self, md: markdown.Markdown, config: Mapping[str, Any]) -> None:
super().__init__(md) super().__init__(md)
self.base_path = config["base_path"]
def run(self, lines: List[str]) -> List[str]: def run(self, lines: List[str]) -> List[str]:
done = False done = False
@@ -83,17 +71,7 @@ class APIArgumentsTablePreprocessor(Preprocessor):
if not match: if not match:
continue continue
filename = match.group(1)
doc_name = match.group(2) doc_name = match.group(2)
filename = os.path.expanduser(filename)
is_openapi_format = filename.endswith(".yaml")
if not os.path.isabs(filename):
parent_dir = self.base_path
filename = os.path.normpath(os.path.join(parent_dir, filename))
if is_openapi_format:
endpoint, method = doc_name.rsplit(":", 1) endpoint, method = doc_name.rsplit(":", 1)
arguments: List[Dict[str, Any]] = [] arguments: List[Dict[str, Any]] = []
@@ -105,16 +83,12 @@ class APIArgumentsTablePreprocessor(Preprocessor):
# endpoint doesn't accept any parameters # endpoint doesn't accept any parameters
if e.args != ("parameters",): if e.args != ("parameters",):
raise e raise e
else:
with open(filename) as fp:
json_obj = json.load(fp)
arguments = json_obj[doc_name]
if arguments: if arguments:
text = self.render_parameters(arguments) text = self.render_parameters(arguments)
# We want to show this message only if the parameters # We want to show this message only if the parameters
# description doesn't say anything else. # description doesn't say anything else.
elif is_openapi_format and get_parameters_description(endpoint, method) == "": elif get_parameters_description(endpoint, method) == "":
text = ["This endpoint does not accept any parameters."] text = ["This endpoint does not accept any parameters."]
else: else:
text = [] text = []
@@ -289,7 +263,7 @@ class APIArgumentsTablePreprocessor(Preprocessor):
def makeExtension(*args: Any, **kwargs: str) -> MarkdownArgumentsTableGenerator: def makeExtension(*args: Any, **kwargs: str) -> MarkdownArgumentsTableGenerator:
return MarkdownArgumentsTableGenerator(kwargs) return MarkdownArgumentsTableGenerator(*args, **kwargs)
def generate_data_type(schema: Mapping[str, Any]) -> str: def generate_data_type(schema: Mapping[str, Any]) -> str:

View File

@@ -119,9 +119,7 @@ def render_markdown_path(
zerver.lib.markdown.fenced_code.makeExtension( zerver.lib.markdown.fenced_code.makeExtension(
run_content_validators=context.get("run_content_validators", False), run_content_validators=context.get("run_content_validators", False),
), ),
zerver.lib.markdown.api_arguments_table_generator.makeExtension( zerver.lib.markdown.api_arguments_table_generator.makeExtension(),
base_path="templates/zerver/api/"
),
zerver.lib.markdown.api_return_values_table_generator.makeExtension(), zerver.lib.markdown.api_return_values_table_generator.makeExtension(),
zerver.lib.markdown.nested_code_blocks.makeExtension(), zerver.lib.markdown.nested_code_blocks.makeExtension(),
zerver.lib.markdown.tabbed_sections.makeExtension(), zerver.lib.markdown.tabbed_sections.makeExtension(),