-
Notifications
You must be signed in to change notification settings - Fork 45
validate spec #253
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
base: master
Are you sure you want to change the base?
validate spec #253
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(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. |
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.