From 600fd9404123e0b7fb537df6b21b0a8a098e7941 Mon Sep 17 00:00:00 2001 From: myrfy001 Date: Thu, 8 Nov 2018 17:17:21 +0800 Subject: [PATCH 1/2] fix sanic missing import --- swagger_py_codegen/templates/sanic/schemas.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swagger_py_codegen/templates/sanic/schemas.tpl b/swagger_py_codegen/templates/sanic/schemas.tpl index fd90c23..6d1f7f9 100644 --- a/swagger_py_codegen/templates/sanic/schemas.tpl +++ b/swagger_py_codegen/templates/sanic/schemas.tpl @@ -4,6 +4,7 @@ {% include '_do_not_change.tpl' %} import six +from jsonschema import RefResolver base_path = '{{base_path}}' @@ -58,4 +59,3 @@ security = Security() {{ merge_default }} {{ normalize }} - From 07be88992c6811bdb690ad83c7949349085256d9 Mon Sep 17 00:00:00 2001 From: myrfy001 Date: Thu, 8 Nov 2018 17:17:49 +0800 Subject: [PATCH 2/2] port $ref support for sanic from flask --- swagger_py_codegen/templates/sanic/validators.tpl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/swagger_py_codegen/templates/sanic/validators.tpl b/swagger_py_codegen/templates/sanic/validators.tpl index c5edc4d..e295418 100644 --- a/swagger_py_codegen/templates/sanic/validators.tpl +++ b/swagger_py_codegen/templates/sanic/validators.tpl @@ -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') @@ -189,4 +196,4 @@ def response_filter(view): headers=headers, ) - return wrapper + return wrapper \ No newline at end of file