api docs: Read parameters and response fixtures from OpenAPI files.

This commit is contained in:
Yago González
2018-05-15 19:28:42 +02:00
parent 30682241c7
commit f84c9b919b
10 changed files with 100 additions and 35 deletions

26
zerver/lib/openapi.py Normal file
View 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'])