-
-
Notifications
You must be signed in to change notification settings - Fork 840
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
fix: invalid nullable enums with OAS 3.1 version #2226
fix: invalid nullable enums with OAS 3.1 version #2226
Conversation
This should be fixed inside swagger-php and yes you are correct zircote/swagger-php#1528 & zircote/swagger-php#1531 are related to this issue. All OpenApi version conversions are done inside swagger-php's https://github.com/zircote/swagger-php/blob/4.8.4/src/Annotations/AbstractAnnotation.php#L390. |
I don't think potentially adding a bunch of if-statements everywhere to fix the spec for specific openapi versions is the right way to go inside this codebase (nelmio) either. A processor(s) on swagger-php's end to convert generated specs for different versions would be a good way to handle these things. |
@DjordyKoert I'd treat it as a workaround solution, which should be replaced by version dependent processors in the future. I'll continue the topic on swagger-php's end and we'll see how it envolves. |
Hello again @DjordyKoert I played a bit with swagger-php and it looks it's a bigger more complex topic than I thought :) Will try to summarize it: Originally I tried to handle current behavior of nelmio (which wraps enums with
When I wanted to add additional property annotation to force using All of above turned me to thinking whether wrapping enums with now short question (I promise 😅) - why do we need to wrap enums by |
Just had a small look at the openapi spec and I just now noticed that our nullable are just incorrect currently as can be seen here at "Nullable enums" https://swagger.io/docs/specification/data-models/enums/.
|
Hello @DjordyKoert The spec you sent is dedicated only for OAS 3.0 version, and there's That's true, that I think the spec with
So basically it's version for OAS 3.1, but it's backward compatibility with OAS 3.0 Addressing your suggestions:
I wouldn't treat nullable enums properties, in the same way as I would be happy to implement solution as proposed (with |
2930c2f
to
6cac88a
Compare
The main reason for using this is because the swagger editor does not show a proper input field when using There is also an open issue on swagger-ui swagger-api/swagger-ui#7912 A fix suitable fix for both openapi versions (3.0 & 3.1) would be by doing one of the things I mentioned earlier #2226 (comment) or by keeping as it is (even if |
ok I've got it now, thanks. I've added one question to swagger-ui issue for more context. However, returning back to the issue:
Keeping as it is (with |
I stand corrected, I have done some testing with the swagger editor (https://editor.swagger.io/ & https://editor-next.swagger.io/) and my potential 'fixes' and none of those are properly visible OR they simply send incorrect data (when using openapi: 3.0.0
paths:
/1:
get:
parameters:
- name: order
in: query
description: oneOf does not create a dropdown.
schema:
oneOf:
- $ref: '#/components/schemas/SortOrder'
/2:
get:
parameters:
- name: order
in: query
description: allOf DOES create dropdown.
schema:
allOf:
- $ref: '#/components/schemas/SortOrder'
/3:
get:
parameters:
- name: order
in: query
description: allOf with nullable does not show null as an option
schema:
nullable: true
allOf:
- $ref: '#/components/schemas/SortOrder'
/4:
get:
parameters:
- name: order
in: query
description: allOf with nullable does not allow sending a null value
required: true
schema:
nullable: true
$ref: '#/components/schemas/SortOrder'
/5:
get:
parameters:
- name: order
in: query
description: NullableSortOrder sends ?order=null which does not get handles by Symfony's MapQueryParameter properly (results in an exception being thrown)
required: true
schema:
$ref: '#/components/schemas/NullableSortOrder'
components:
schemas:
SortOrder:
type: string
enum:
- ascending
- descending
NullableSortOrder:
type: string
nullable: true
enum:
- ascending
- descending
- null My conclusion:Let's always use |
cool, so I'll adjust PR accordingly :) Thanks for involving into the topic and being so responsively 👍 |
6cac88a
to
32de004
Compare
@DjordyKoert done, ready for review |
Thank you @bnowak! |
Fix from #2178 solved proper describing of nullable enums for OAS v 3.0, but it seems that broke it for OAS v 3.1.
As for version 3.0 it's correct and looks like:
for version 3.1 it seems to be wrong. It's impossible to match these both types at the same time:
I think the correct version for 3.1 should be:
In our project we're validating API data responses against API model schema using https://github.com/opis/json-schema and it reports above issue.
For now it's a dirty/draft PR to demonstrate the issue and start the discussion. It includes possible solution but I'm not sure 100% it's the correct way:
Seems to be also connected with zircote/swagger-php#1528 and zircote/swagger-php#1531, is that right @DjordyKoert?
I'm happy to finalize this topic, but please point me in the right direction. Any feedback is welcome :)