Closed Alive24 closed 5 years ago
Hey @xct24 I've just checked your specs and I did found 2 issues on them.
In [1]: from swagger_spec_validator.validator20 import validate_spec_url
In [2]: # NOTE: I'm on OSX so the path could look different
In [3]: validate_spec_url('file:///Users/maci/Desktop/specs.yaml')
...
SwaggerValidationError: ('("{\'description\': \'登陆失败\', \'schema\': {\'$ref\': \'#/responses/UnauthorizedError\', \'x-scope\': [\'file:///Users/maci/Desktop/specs.yaml\']}} is not valid under any of the given schemas\\n\\nFailed validating \'oneOf\' in schema[\'properties\'][\'paths\'][\'patternProperties\'][\'^/\'][\'properties\'][\'head\'][\'properties\'][\'responses\'][\'patternProperties\'][\'^([0-9]{3})$|^(default)$\']:\\n {\'oneOf\': [{\'$ref\': \'#/definitions/response\'},\\n {\'$ref\': \'#/definitions/jsonReference\'}]}\\n\\nOn instance[\'paths\'][\'/learner\'][\'head\'][\'responses\'][\'401\']:\\n {\'description\': \'登陆失败\',\\n \'schema\': {\'$ref\': \'#/responses/UnauthorizedError\',\\n \'x-scope\': [\'file:///Users/maci/Desktop/specs.yaml\']}}", <ValidationError: "{\'description\': \'登陆失败\', \'schema\': {\'$ref\': \'#/responses/UnauthorizedError\', \'x-scope\': [\'file:///Users/maci/Desktop/specs.yaml\']}} is not valid under any of the given schemas">)', SwaggerValidationError("{'description': '登陆失败', 'schema': {'$ref': '#/responses/UnauthorizedError', 'x-scope': ['file:///Users/maci/Desktop/specs.yaml']}} is not valid under any of the given schemas\n\nFailed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^/']['properties']['head']['properties']['responses']['patternProperties']['^([0-9]{3})$|^(default)$']:\n {'oneOf': [{'$ref': '#/definitions/response'},\n {'$ref': '#/definitions/jsonReference'}]}\n\nOn instance['paths']['/learner']['head']['responses']['401']:\n {'description': '登陆失败',\n 'schema': {'$ref': '#/responses/UnauthorizedError',\n 'x-scope': ['file:///Users/maci/Desktop/specs.yaml']}}", <ValidationError: "{'description': '登陆失败', 'schema': {'$ref': '#/responses/UnauthorizedError', 'x-scope': ['file:///Users/maci/Desktop/specs.yaml']}} is not valid under any of the given schemas">))
In [4]: # The issue is not really expressive, so I did extract the inner validation error
In [5]: try:
...: validator20.validate_spec_url('file:///Users/maci/Desktop/specs.yaml')
...: except Exception as e:
...: print(e.args[1].args[1])
...:
{'description': '登陆失败', 'schema': {'$ref': '#/responses/UnauthorizedError', 'x-scope': ['file:///Users/maci/Desktop/specs.yaml']}} is not valid under any of the given schemas
Failed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^/']['properties']['head']['properties']['responses']['patternProperties']['^([0-9]{3})$|^(default)$']:
{'oneOf': [{'$ref': '#/definitions/response'},
{'$ref': '#/definitions/jsonReference'}]}
On instance['paths']['/login']['post']['responses']['401']:
{'description': '登陆失败',
'schema': {'$ref': '#/responses/UnauthorizedError',
'x-scope': ['file:///Users/maci/Desktop/specs.yaml']}}
Checking the specs for instance['paths']['/login']['post']['responses']['401']
I see that it is defined as:
'401':
description: 登陆失败
schema:
$ref: "#/responses/UnauthorizedError"
but #/responses/UnauthorizedError
is a valid response object and not a valid schema object.
Checking other usage of the object in the specs I see something like
'401':
$ref: "#/responses/UnauthorizedError"
By fixing that occurrence and an other one (again reported with the same method above) the validation passes
In [7]: try:
...: validator20.validate_spec_url('file:///Users/maci/Desktop/fixed.yaml')
...: except Exception as e:
...: print(e.args[1].args[1])
...:
In [8]:
Spec diff
--- /Users/maci/Desktop/specs.yaml Thu Dec 13 17:59:57 2018
+++ /Users/maci/Desktop/fixed.yaml Thu Dec 13 18:00:11 2018
@@ -331,9 +331,7 @@
schema:
$ref: '#/definitions/TokenStatus'
'401':
- description: 登陆失败
- schema:
- $ref: "#/responses/UnauthorizedError"
+ $ref: "#/responses/UnauthorizedError"
/learner:
head:
summary: 返回所有Learner的关键信息
@@ -352,9 +350,7 @@
type: string
example: John Appleseed
'401':
- description: 登陆失败
- schema:
- $ref: "#/responses/UnauthorizedError"
+ $ref: "#/responses/UnauthorizedError"
get:
summary: 返回所有的Leaner详细信息
tags:
Thank you! Problem solved
Hi there, I tried to get an issue solved when I was using Swagger Editor and the python-flask code it generated, and I was referred to your project.
One of their people believed that
The link to the issue: https://github.com/swagger-api/swagger-editor/issues/1912
Thank you!
I also attached the original post just FYI.