Fix swagger errors

Fixes #287
This commit is contained in:
Joseph Schorr 2015-07-29 18:25:44 -04:00
parent 572d6ba53c
commit 5c1d195a19
14 changed files with 57 additions and 57 deletions

View file

@ -3,6 +3,7 @@
import re
import logging
import sys
import copy
from flask.ext.restful import reqparse
@ -35,7 +36,6 @@ def fully_qualified_name(method_view_class):
def swagger_route_data(include_internal=False, compact=False):
def swagger_parameter(name, description, kind='path', param_type='string', required=True,
enum=None, schema=None):
# https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#parameterObject
@ -60,7 +60,6 @@ def swagger_route_data(include_internal=False, compact=False):
return parameter_info
paths = {}
models = {}
tags = []
@ -92,16 +91,17 @@ def swagger_route_data(include_internal=False, compact=False):
# Build the Swagger data for the path.
swagger_path = PARAM_REGEX.sub(r'{\2}', rule.rule)
full_name = fully_qualified_name(view_class)
path_swagger = {
'name': fully_qualified_name(view_class),
'path': swagger_path,
'tag': tag_name
'x-name': full_name,
'x-path': swagger_path,
'x-tag': tag_name
}
if include_internal:
related_user_res = method_metadata(view_class, 'related_user_resource')
if related_user_res is not None:
path_swagger['quay_user_related'] = fully_qualified_name(related_user_res)
path_swagger['x-user-related'] = fully_qualified_name(related_user_res)
paths[swagger_path] = path_swagger
@ -138,12 +138,12 @@ def swagger_route_data(include_internal=False, compact=False):
# Mark the method as internal.
internal = method_metadata(method, 'internal')
if internal is not None:
operation_swagger['internal'] = True
operation_swagger['x-internal'] = True
if include_internal:
requires_fresh_login = method_metadata(method, 'requires_fresh_login')
if requires_fresh_login is not None:
operation_swagger['requires_fresh_login'] = True
operation_swagger['x-requires-fresh-login'] = True
# Add the path parameters.
if rule.arguments:
@ -169,14 +169,49 @@ def swagger_route_data(include_internal=False, compact=False):
# https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#securityRequirementObject
scope = method_metadata(method, 'oauth2_scope')
if scope and not compact:
operation_swagger['security'] = [{'oauth2_implicit': scope.scope}]
operation_swagger['security'] = [{'oauth2_implicit': [scope.scope]}]
# TODO: Add the responses block.
# Add the responses block.
# https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#responsesObject
response_schema_name = method_metadata(method, 'response_schema')
if response_schema_name and not compact:
models[response_schema_name] = view_class.schemas[response_schema_name]
response_type = response_schema_name
if not compact:
if response_schema_name:
models[response_schema_name] = view_class.schemas[response_schema_name]
responses = {
'400': {
'description': 'Bad Request'
},
'401': {
'description': 'Session required'
},
'403': {
'description': 'Unauthorized access'
},
'404': {
'description': 'Not found'
},
}
if method_name == 'DELETE':
responses['204'] = {
'description': 'Deleted'
}
else:
responses['200'] = {
'description': 'Successful invocation'
}
if response_schema_name:
responses['200']['schema'] = {
'$ref': '#/definitions/%s' % response_schema_name
}
operation_swagger['responses'] = responses
# Add the request block.
request_schema_name = method_metadata(method, 'request_schema')
@ -192,7 +227,7 @@ def swagger_route_data(include_internal=False, compact=False):
path_swagger[method_name.lower()] = operation_swagger
tags.sort(key=lambda t: t['name'])
paths = OrderedDict(sorted(paths.items(), key=lambda p: p[1]['tag']))
paths = OrderedDict(sorted(paths.items(), key=lambda p: p[1]['x-tag']))
if compact:
return {'paths': paths}