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: correct OpenAPI schema for enum constraints (#2812) #2818
Conversation
Thanks for this! I'm out of time to review it for now, but will get to it ASAP, or someone else will. Are those type check failures issues with the way we have the properties typed on the spec models? |
@all-contributors add @hzhou0 for bug and code |
I've put up a pull request to add @hzhou0! 🎉 |
I fixed most of it, the problem is TYPE_MAP in schema.py. It has Schema values, which have type: OpenAPIType | Sequence[OpenAPIType] | None, however in that map it could be narrowed to type: OpenAPIType. I tried to typeguard, but not sure how to do that against Sequence types. |
This PR fixes OpenAPI schema generation when enum constraints are present, such as in python Enums or Literal types. The JSONSchema "type" constraint is now a list of all types present in the enum constraints, which is the specified schema expectation. Fixes tests to expect this behaviour.
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.
LGTM. Thanks @hzhou0
Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/2818 |
Pull Request Checklist
Description
Close Issue(s)