Conversation
E openapi_spec_validator.validation.exceptions.OpenAPIValidationError: {} should be non-empty
E
E Failed validating 'minProperties' in schema['properties']['paths']['patternProperties']['^/']['else']['properties']['get']['properties']['responses']:
E {'$comment': 'https://spec.openapis.org/oas/v3.1.0#responses-object',
E 'type': 'object',
E 'properties': {'default': {'$ref': '#/$defs/response-or-reference'}},
E 'patternProperties': {'^[1-5](?:[0-9]{2}|XX)$': {'$ref': '#/$defs/response-or-reference'}},
E 'minProperties': 1,
E '$ref': '#/$defs/specification-extensions',
E 'unevaluatedProperties': False,
E 'if': {'$comment': 'either default, or at least one response code '
E 'property must exist',
E 'patternProperties': {'^[1-5](?:[0-9]{2}|XX)$': False}},
E 'then': {'required': ['default']}}
E
E On instance['paths']['/book']['get']['responses']:
E {}
- Remove 'default' key if it's None to maintain OpenAPI spec compliance. - Only return valid links. - validate schemas in all tests I am not entirely happy with the links, because we silently ignore things that the user provided. We should either - raise exceptions and change the tests, so that only valid links can be specified (my preferred option) or - warn the user. I did not implement this, because logging is not used at all and I wanted to keep the library's style intact.
| @model_serializer(mode="wrap", when_used="json") | ||
| def _serialize(self, serializer, info): | ||
| data = serializer(self) | ||
| # Remove 'default' key if it's None to maintain OpenAPI spec compliance |
There was a problem hiding this comment.
(IIRC) There are cases when "default=None" is needed to be documented. Like, the field requires a value, None is valid, and it's the default. I already use openapi-spec-validator and don't see what validation it breaks though from a quick check of the pull request.
|
@felixhummel Thanks for your contribution, validating against the OpenAPI specification is more secure. I don't think You should create a new test script instead of modifying all existing tests, which is not good for maintenance. |
|
@luolingchun Thanks for taking the time to read this! I believe that every spec that is generated by flask-openapi3 should be valid OAS 3.0 or OAS 3.1 depending on the the value of info.version as passed to |
We need clean specs to generate clean clients.
I propose to validate the spec in the tests.
I also made changes to make the spec compliant.
Please note my comment in cd496a5 concerning links.
Checklist:
pytest testsand no failed.ruff check flask_openapi3 tests examplesand no failed.ruff format flask_openapi3 tests examplesand no failed.mypy flask_openapi3and no failed.mkdocs serveand no failed.