-
-
Notifications
You must be signed in to change notification settings - Fork 402
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: openapi schema for literal and enum unions with None. #2550
Conversation
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.
Im going to try this out at work since i hit this issue
Running with {
"status_code": 400,
"detail": "Validation failed for GET http://127.0.0.1:8000/",
"extra": [
{
"message": "Expected `str`, got `null`",
"key": "environment",
"source": "query"
}
]
} |
Is this with |
Can you elaborate? If it's not |
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.
Good stuff, just some nits you can feel free to ignore :)
8f62802
to
fcc0ee9
Compare
Existing behavior is to make the schema for every type that is a union with `None` a "one_of" schema, that includes `OpenAPIType.NULL` in the "one_of" types. https://github.com/litestar-org/litestar/blob/5db8d81fbf24788d38d210e90300e5f0926f830a/litestar/_openapi/schema_generation/schema.py#L319-L340 When a `Literal` or `Enum` type is in a union with `None`, this behavior is not desirable, as we want to have `null` available in the list of available options on the type's schema. This PR changes literal and enum schema generation so that it can be identified that the types are in a union with `None`, allowing `null` to be included in `Schema.enum` values. Closes #2456
…refactored) (#2551) 'Refactored by Sourcery' Co-authored-by: Sourcery AI <>
Co-authored-by: Janek Nouvertné <provinzkraut@posteo.de>
Co-authored-by: Janek Nouvertné <provinzkraut@posteo.de>
fcc0ee9
to
9c7f767
Compare
Kudos, SonarCloud Quality Gate passed! |
Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/2550 |
Pull Request Checklist
Description
Existing behavior is to make the schema for every type that is a union with
None
a "one_of" schema, that includesOpenAPIType.NULL
in the "one_of" types.litestar/litestar/_openapi/schema_generation/schema.py
Lines 319 to 340 in 5db8d81
When a
Literal
orEnum
type is in a union withNone
, this behavior is not desirable, as we want to havenull
available in the list of available options on the type's schema.This PR changes literal and enum schema generation so that it can be identified that the types are in a union with
None
, allowingnull
to be included inSchema.enum
values.Close Issue(s)
Closes #2546