mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
api docs: Read parameters and response fixtures from OpenAPI files.
This commit is contained in:
@@ -7,11 +7,13 @@ import inspect
|
||||
from markdown.extensions import Extension
|
||||
from markdown.preprocessors import Preprocessor
|
||||
from typing import Any, Dict, Optional, List
|
||||
from yamole import YamoleParser
|
||||
import markdown
|
||||
|
||||
import zerver.lib.api_test_helpers
|
||||
from zerver.lib.openapi import get_openapi_fixture
|
||||
|
||||
MACRO_REGEXP = re.compile(r'\{generate_code_example(\(\s*(.+?)\s*\))*\|\s*(.+?)\s*\|\s*(.+?)\s*(\(\s*(.+?)\s*\))?\}')
|
||||
MACRO_REGEXP = re.compile(r'\{generate_code_example(\(\s*(.+?)\s*\))*\|\s*(.+?)\s*\|\s*(.+?)\s*(\(\s*(.+)\s*\))?\}')
|
||||
CODE_EXAMPLE_REGEX = re.compile(r'\# \{code_example\|\s*(.+?)\s*\}')
|
||||
|
||||
PYTHON_CLIENT_CONFIG = """
|
||||
@@ -138,8 +140,12 @@ class APICodeExamplesPreprocessor(Preprocessor):
|
||||
def render_fixture(self, function: str, name: Optional[str]=None) -> List[str]:
|
||||
fixture = []
|
||||
|
||||
if name:
|
||||
fixture_dict = zerver.lib.api_test_helpers.FIXTURES[function][name]
|
||||
# We assume that if the function we're rendering starts with a slash
|
||||
# it's a path in the endpoint and therefore it uses the new OpenAPI
|
||||
# format.
|
||||
if function.startswith('/'):
|
||||
path, method = function.rsplit(':', 1)
|
||||
fixture_dict = get_openapi_fixture(path, method, name)
|
||||
else:
|
||||
fixture_dict = zerver.lib.api_test_helpers.FIXTURES[function]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user