mirror of
https://github.com/zulip/zulip.git
synced 2025-10-31 20:13:46 +00:00
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:
committed by
Tim Abbott
parent
f38d5a6a26
commit
b64d8e8a52
@@ -1,5 +1,4 @@
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from typing import Any, Dict, List, Mapping, Sequence
|
||||
|
||||
@@ -50,16 +49,6 @@ OBJECT_CODE_TEMPLATE = "<code>{value}</code>".strip()
|
||||
|
||||
|
||||
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:
|
||||
md.preprocessors.register(
|
||||
APIArgumentsTablePreprocessor(md, self.getConfigs()),
|
||||
@@ -71,7 +60,6 @@ class MarkdownArgumentsTableGenerator(Extension):
|
||||
class APIArgumentsTablePreprocessor(Preprocessor):
|
||||
def __init__(self, md: markdown.Markdown, config: Mapping[str, Any]) -> None:
|
||||
super().__init__(md)
|
||||
self.base_path = config["base_path"]
|
||||
|
||||
def run(self, lines: List[str]) -> List[str]:
|
||||
done = False
|
||||
@@ -83,38 +71,24 @@ class APIArgumentsTablePreprocessor(Preprocessor):
|
||||
if not match:
|
||||
continue
|
||||
|
||||
filename = match.group(1)
|
||||
doc_name = match.group(2)
|
||||
filename = os.path.expanduser(filename)
|
||||
endpoint, method = doc_name.rsplit(":", 1)
|
||||
arguments: List[Dict[str, Any]] = []
|
||||
|
||||
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)
|
||||
arguments: List[Dict[str, Any]] = []
|
||||
|
||||
try:
|
||||
arguments = get_openapi_parameters(endpoint, method)
|
||||
except KeyError as e:
|
||||
# Don't raise an exception if the "parameters"
|
||||
# field is missing; we assume that's because the
|
||||
# endpoint doesn't accept any parameters
|
||||
if e.args != ("parameters",):
|
||||
raise e
|
||||
else:
|
||||
with open(filename) as fp:
|
||||
json_obj = json.load(fp)
|
||||
arguments = json_obj[doc_name]
|
||||
try:
|
||||
arguments = get_openapi_parameters(endpoint, method)
|
||||
except KeyError as e:
|
||||
# Don't raise an exception if the "parameters"
|
||||
# field is missing; we assume that's because the
|
||||
# endpoint doesn't accept any parameters
|
||||
if e.args != ("parameters",):
|
||||
raise e
|
||||
|
||||
if arguments:
|
||||
text = self.render_parameters(arguments)
|
||||
# We want to show this message only if the parameters
|
||||
# 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."]
|
||||
else:
|
||||
text = []
|
||||
@@ -289,7 +263,7 @@ class APIArgumentsTablePreprocessor(Preprocessor):
|
||||
|
||||
|
||||
def makeExtension(*args: Any, **kwargs: str) -> MarkdownArgumentsTableGenerator:
|
||||
return MarkdownArgumentsTableGenerator(kwargs)
|
||||
return MarkdownArgumentsTableGenerator(*args, **kwargs)
|
||||
|
||||
|
||||
def generate_data_type(schema: Mapping[str, Any]) -> str:
|
||||
|
||||
@@ -119,9 +119,7 @@ def render_markdown_path(
|
||||
zerver.lib.markdown.fenced_code.makeExtension(
|
||||
run_content_validators=context.get("run_content_validators", False),
|
||||
),
|
||||
zerver.lib.markdown.api_arguments_table_generator.makeExtension(
|
||||
base_path="templates/zerver/api/"
|
||||
),
|
||||
zerver.lib.markdown.api_arguments_table_generator.makeExtension(),
|
||||
zerver.lib.markdown.api_return_values_table_generator.makeExtension(),
|
||||
zerver.lib.markdown.nested_code_blocks.makeExtension(),
|
||||
zerver.lib.markdown.tabbed_sections.makeExtension(),
|
||||
|
||||
Reference in New Issue
Block a user