-
Notifications
You must be signed in to change notification settings - Fork 91
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
OpenAPI 3.0.3 Schema Incorrectly Includes enum: [null] When Description is Present in @Schema Annotation #2145
Comments
Hmm, some interesting things going on here.
Internally, we use the OpenAPI 3.1 model right up until we serialize. The code that does the transformation of 3.1 -> 3.0 schema is in SchemaIO so likely something is wrong here. In general this pattern is annoying to translate. In OpenAPI 3.0 you could do this: mySchema:
allOf:
- $ref: "#/components/schemas/aSchema"
nullable: true Whereas in OpenAPI 3.1, mySchema:
anyOf:
- $ref: "#/components/schemas/aSchema"
- type: "null" I will have a look to see what's going wrong here. |
@Azquelt , Thank you for looking into it. Sorry for the confusion, Subject:
enum:
- ALICE
- BOB
type: string Please let me know if you would like me to attach a reproducer project for this issue. Thank you! |
Ok, I think I see why this happens any why having a description makes a difference.
In this case we end up with something like: $ref: "#/components/schema/MyType" However, if there are additional properties on the field, it will add a reference to the schema for the field, drop any properties that match and add a type observer, which synchronises the type of the field with the type of the referenced schema. In that case, we end up with something like: $ref: "#/components/schema/MyType"
type: ["object", "null"]
description: My field description Then, if the field is nullable but the referenced schema isn't, we turn that into this: type: ["object", "null"]
anyOf:
- $ref: "#/components/schema/MyType"
- type: "null"
description: My field description Finally, when we serialize, we convert this OpenAPI 3.1 model into OpenAPI 3.0 format and we have this check for turning an I think we can remove that last part of the check. I just need to add some tests. |
Description:
When generating OpenAPI 3.0.3 schema using SmallRye OpenAPI, if a field's @Schema annotation includes a description, the generator incorrectly adds enum: [null] to the schema for nullable fields. This doesn't occur when the description is omitted.
Example code:
Code:
Configuration:
application.properties
force OpenAPI to3.0.3
mp.openapi.extensions.smallrye.openapi=3.0.3
Resulting Schema
Issue:
I'm using quarkus 3.17.5, which includes io.smallrye:smallrye-open-api-core:4.0.5.
Thank you for your help!
The text was updated successfully, but these errors were encountered: