Unnecessary Union for Same-Type Sequence Members #1205
Unanswered
michaeligreenberg
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Here's an example FastAPI app:
Using
datamodel-codegen
with the--use-generic-container-types
option on the response from the app's/openapi.json
endpoint produces the following schema:Besides the Pydantic v1 problem of unenforced field constraints on a generic, I also noticed that the coordinates field has the repetitive generic type of
Sequence[Union[float, float]]
; I believe that justSequence[float]
would suffice. A possible improvement would be to detect when there is only one possible type and omit the Union.Details
fastapi 0.95.0
datamodel-codegen 0.17.1
Beta Was this translation helpful? Give feedback.
All reactions