-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
[Feature] Loosen up casting/validation logic (enforced by enums) #40
Comments
Hey @sergei-maertens, thanks for your suggestion. Actually, I agree with you that it's could be incorrect to prevent allowed values by the specification. Those enumerations were created according to basic Open API specifications and don't include all possible values. Since changes you suggested might break backward compatibility, I'd suggest using optional parser parameter which can be used for disabling strict enumerations like Btw, I will re-think this feature for the next major release accordingly. |
For now I was able to work around it and build on top of your parser by defining a custom I shall draft up a PR! |
Certain schema properties (content types, type formats...) are not limited to a known set of values in the OpenAPI 3.x specification. Users can opt-in for non-strict enum evaluation, making it possible to parse specifications with custom content types and/or formats used in schema definitions.
Certain schema properties (content types, type formats...) are not limited to a known set of values in the OpenAPI 3.x specification. Users can opt-in for non-strict enum evaluation, making it possible to parse specifications with custom content types and/or formats used in schema definitions.
Certain schema properties (content types, type formats...) are not limited to a known set of values in the OpenAPI 3.x specification. Users can opt-in for non-strict enum evaluation, making it possible to parse specifications with custom content types and/or formats used in schema definitions.
Certain schema properties (content types, type formats...) are not limited to a known set of values in the OpenAPI 3.x specification. Users can opt-in for non-strict enum evaluation, making it possible to parse specifications with custom content types and/or formats used in schema definitions.
What is a problem?
I have some API schemas that use less-obvious (valid) OpenAPI constructs that are not supported by this library because of the hardcoded strictness in the
openapi_parser.enumeration
module.For example - error responses follow RFC 7807, which results in the responses having a
application/problem+json
Content Type - which is not present in theContentType
enum. As far as I'm aware, using custom content types is supported in OpenAPI 3 (and the underlyingprance
library also doesn't seem to complain about this).Another example is the
type: string
andformat: duration
specification - onlydate-time
is present in theStringFormat
, whileduration
maps to the ISO8601 durations. The OAS 3 spec explicitly mentions thatformat
is an open value:Describe the solution you'd like
Values not present in the enums should not raise exceptions, but be silently accepted _as long as they comply with the OpenAPI 3 specification. This may even remove the need completely for the enums.
Alternatively, a register-approach for these enums could be useful so that library-users can add their own (common) definitions, as this information can help in emitting python type hints and down the road maybe even in generating API clients with the correct casting operations (e.g. formatting a python
timedelta
orrelativedelta
into an ISO8601 string during serialization).Describe alternatives you've considered
Currently I can use
aenum
to extend the enums and add extra formats, but this is not sustainable as it only works for formats/content-types present in the API schema's to parse. In building a more generic tool to compare equivalency of mulitple API specs, this should be able to handle any unseen-before specifications thrown at it.Additional context
I'm investigation options for OpenAPI-parsing libraries so that I can build a tool to compare equivalency. Your use of dataclasses and dedicated python types for API schema objects is well suited to that and I'd prefer using that over having to process the python dicts/lists from raw underlying data.
The text was updated successfully, but these errors were encountered: