-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
✨ Allow array values for OpenAPI schema type field
#13639
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
✨ Allow array values for OpenAPI schema type field
#13639
Conversation
|
Hey @svlandeg thanks for adding the label, what does the review process look like and can I help out in anyway? 😄 |
Co-authored-by: dlax <[email protected]>
3ae5fab to
3cd4f27
Compare
|
@YuriiMotov Added some tests, but the change in this PR is quite small and is only made to allow for type to be a str and list. But since there is no field validator for type its still possible to break the json schema. (by setting type to a empty list or by adding duplicates. https://json-schema.org/draft/2020-12/json-schema-validation#section-6.1.1 ) But I think this is a good start and more validation can be added later. wdyt? |
YuriiMotov
left a comment
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.
Let's reduce the number of test a bit :)
Just test that all valid types are accepted and maybe add one test for validation error on passing incorrect type
Added some tests, but the change in this PR is quite small and is only made to allow for type to be a str and list. But since there is no field validator for type its still possible to break the json schema. (by setting type to a empty list or by adding duplicates
But I think this is a good start and more validation can be added later. wdyt?
I agree, no need to add this validation now.
86795bb to
13f918c
Compare
13f918c to
9379506
Compare
Co-authored-by: Motov Yurii <[email protected]>
type field
YuriiMotov
left a comment
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
@sammasak, thanks!
tiangolo
left a comment
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.
Sounds good, thanks! 🚀
I tweaked it a bit to put the OpenAPI types and related on the same file, it should be ready now. 🍰
Allow Union Types in OpenAPI Schemas
This PR addresses an issue with how union types for the "type" field are validated in FastAPI's OpenAPI generation. Currently, only a string is allowed for the type definition even though the JSON Schema specification (Section 6.1.1) permits the value to be either a string or an array of unique string values. This discrepancy can lead to confusion or incorrect schema validation when using union types.
Example here that throws pydantic validation error:
Addressed by introducing
TypeValue, defined as an annotated literal that encompasses the valid JSON Schema types.And updating the Schema model to use the literal values.
After these changes the validation error is removed.