Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix missing import and $ref support for sanic #131

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion swagger_py_codegen/templates/sanic/schemas.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

{% include '_do_not_change.tpl' %}
import six
from jsonschema import RefResolver

base_path = '{{base_path}}'

Expand Down Expand Up @@ -58,4 +59,3 @@ security = Security()
{{ merge_default }}

{{ normalize }}

9 changes: 8 additions & 1 deletion swagger_py_codegen/templates/sanic/validators.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ class SanicValidatorAdaptor(object):
for k, values in obj.items():
prop = self.validator.schema['properties'].get(k, {})
type_ = prop.get('type')
if type_ is None and '$ref' in prop:
ref = prop.get('$ref')
if not ref:
continue
type_ = self.validator.resolver.resolve(prop.get('$ref'))[1].get('type')
if not type_:
continue
fun = convert_funs.get(type_, lambda v: v[0])
if type_ == 'array':
item_type = prop.get('items', {}).get('type')
Expand Down Expand Up @@ -189,4 +196,4 @@ def response_filter(view):
headers=headers,
)

return wrapper
return wrapper