mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
api docs: Read parameters and response fixtures from OpenAPI files.
This commit is contained in:
26
zerver/lib/openapi.py
Normal file
26
zerver/lib/openapi.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Set of helper functions to manipulate the OpenAPI files that define our REST
|
||||
# API's specification.
|
||||
import os
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from yamole import YamoleParser
|
||||
|
||||
OPENAPI_SPEC_PATH = os.path.abspath(os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
'../openapi/zulip.yaml'))
|
||||
|
||||
with open(OPENAPI_SPEC_PATH) as file:
|
||||
yaml_parser = YamoleParser(file)
|
||||
|
||||
OPENAPI_SPEC = yaml_parser.data
|
||||
|
||||
|
||||
def get_openapi_fixture(endpoint: str, method: str,
|
||||
response: Optional[str]='200') -> Dict[str, Any]:
|
||||
return (OPENAPI_SPEC['paths'][endpoint][method.lower()]['responses']
|
||||
[response]['content']['application/json']['schema']
|
||||
['example'])
|
||||
|
||||
def get_openapi_parameters(endpoint: str,
|
||||
method: str) -> List[Dict[str, Any]]:
|
||||
return (OPENAPI_SPEC['paths'][endpoint][method]['parameters'])
|
||||
Reference in New Issue
Block a user