More fully replicate the swagger API.

This commit is contained in:
jakedt 2014-03-10 23:54:55 -04:00
parent de1a44f853
commit b3e0dfae48
3 changed files with 157 additions and 43 deletions

View file

@ -1,6 +1,7 @@
import re
from flask.ext.restful import Api, Resource
from flask.ext.restful.utils.cors import crossdomain
from endpoints.api import api, method_metadata, nickname
from endpoints.common import get_route_data
@ -8,11 +9,13 @@ from app import app
discovery_api = Api(api)
discovery_api.decorators = [crossdomain(origin='*')]
param_regex = re.compile(r'<([\w]+:)?([\w]+)>')
def swagger_route_data():
apis = []
models = {}
for rule in app.url_map.iter_rules():
endpoint_method = app.view_functions[rule.endpoint]
@ -30,9 +33,22 @@ def swagger_route_data():
'name': param,
'dataType': 'string',
'description': 'Param description.',
'required': True
'required': True,
})
req_schema_name = method_metadata(method, 'request_schema')
if req_schema_name:
parameters.append({
'paramType': 'body',
'name': 'request_body',
'description': 'Request body contents.',
'dataType': req_schema_name,
'required': True,
})
schema = endpoint_method.view_class.schemas[req_schema_name]
models[req_schema_name] = schema
if method is not None:
operations.append({
'method': method_name,
@ -52,7 +68,9 @@ def swagger_route_data():
'apiVersion': 'v1',
'swaggerVersion': '1.2',
'basePath': 'https://quay.io/',
'resourcePath': '/',
'apis': apis,
'models': models,
}
return swagger_data