[英]Why does apispec validation fail on format similar to documentation example for Python Flask API backend?
I am using apispec in a Python/Flask API backend.我在 Python/Flask API 后端使用 apispec。 i followed the format found in the apispec documentation example.
我遵循了 apispec 文档示例中的格式。 See: https://apispec.readthedocs.io/en/latest/ Can anyone tell me why I am getting a validation error with the below json schema and data?
请参阅: https://apispec.readthedocs.io/en/latest/谁能告诉我为什么我收到以下 json 架构和数据的验证错误? It says "responses" is required but it looks like it is there.
它说“响应”是必需的,但看起来它就在那里。 Is the structure incorrect?
结构不正确? Any help appreciated!
任何帮助表示赞赏!
openapi_spec_validator.exceptions.OpenAPIValidationError: 'responses' is a required propertyFailed validating 'required' in schema['properties']['paths']['patternProperties']['^/']['properties']['get']:
{'additionalProperties': False,
'description': 'Describes a single API operation on a path.',
'patternProperties': {'^x-': {'$ref': '#/definitions/specificationExtension'}},
'properties': {'callbacks': {'$ref': '#/definitions/callbacksOrReferences'},
'deprecated': {'type': 'boolean'},
'description': {'type': 'string'},
'externalDocs': {'$ref': '#/definitions/externalDocs'},
'operationId': {'type': 'string'},
'parameters': {'items': {'$ref': '#/definitions/parameterOrReference'},
'type': 'array',
'uniqueItems': True},
'requestBody': {'$ref': '#/definitions/requestBodyOrReference'},
'responses': {'$ref': '#/definitions/responses'},
'security': {'items': {'$ref': '#/definitions/securityRequirement'},
'type': 'array',
'uniqueItems': True},
'servers': {'items': {'$ref': '#/definitions/server'},
'type': 'array',
'uniqueItems': True},
'summary': {'type': 'string'},
'tags': {'items': {'type': 'string'},
'type': 'array',
'uniqueItems': True}},
'required': ['responses'],
'type': 'object'}
On instance['paths']['/v1/activity']['get']:
{'get': {'description': 'Activity Get',
'responses': {'200': {'content': {'application/json': {'schema': 'ActivitySchema'}},
'description': 'success'}},
'security': [{'AccessTokenAuth': []}],
'tags': ['user', 'admin']}}
For reference, here is the original source comment that the data comes from:
"""
---
get:
description: Activity Get
responses:
200:
description: success
content:
application/json:
schema: ActivitySchema
security:
- AccessTokenAuth: []
tags:
- user
- admin
"""
I found the answer in the apispec documentation at: https://apispec.readthedocs.io/en/latest/using_plugins.html#example-flask-and-marshmallow-plugins where it says: "If your API uses method-based dispatching, the process is similar. Note that the method no longer needs to be included in the docstring."我在 apispec 文档中找到了答案: https://apispec.readthedocs.io/en/latest/using_plugins.html#example-flask-and-marshmallow-plugins上面写着:“如果您的 API 使用基于方法的调度,过程类似。注意该方法不再需要包含在文档字符串中。 This is slightly misleading since it's not "no longer needs to be included" but rather "cannot be included".
这有点误导,因为它不是“不再需要包含”,而是“不能包含”。 So the correct doc string is:
所以正确的文档字符串是:
"""
---
description: Activity Get
responses:
200:
description: success
content:
application/json:
schema: ActivitySchema
security:
- AccessTokenAuth: []
tags:
- user
- admin
"""
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.