You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I already found a issue here which has been closed: #656
I didn't understand the arguments to be honest, However, I think it's just wrong to make it an anyOf.
I tried to post it on FastAPI since it leads to an incorrect openapi.json so I thought maybe a workaround on FastAPI side was meaningful. They forwarded me back here though. tiangolo/fastapi#4959
Best
Stefan
The text was updated successfully, but these errors were encountered:
I agree that this is a bug. I ran into an issue when using openapi-generator to generate a TypeScript SDK from an anyOf discriminated union that was generated by Pydantic. The generated TypeScript code looked incorrect when my models used anyOf, but worked just fine once I switched to oneOf.
Checks
Bug
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:Hi all,
Example from https://pydantic-docs.helpmanual.io/usage/types/#discriminated-unions-aka-tagged-unions:
Using the class Pet above in FastAPI to allow either Cat or Dog as an input leads to an OpenAPI.json which makes Pet like (printed as yaml)
both OpenApi (https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/) and the specification https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#discriminatorObject linked by the pydantic docs (link on top) state that it should be oneOf.
This also corresponds to the "typing" interpretation of Union which is, besides the naming, not a union of the arguments but a "one of those elements"
I already found a issue here which has been closed:
#656
I didn't understand the arguments to be honest, However, I think it's just wrong to make it an anyOf.
I tried to post it on FastAPI since it leads to an incorrect openapi.json so I thought maybe a workaround on FastAPI side was meaningful. They forwarded me back here though.
tiangolo/fastapi#4959
Best
Stefan
The text was updated successfully, but these errors were encountered: