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
avoid misparsing references as other types using Pydantic discriminated unions (#1216)
I’ve found a corner case, I think due to changes to Pydantic’s [smart
mode](https://docs.pydantic.dev/latest/concepts/unions/#smart-mode) for
disambiguating unions, where a subdocument with a `$ref` key and
additional keys (title, description, etc) is validated as a `Schema`
instead of as a `Reference` model. I believe these should be ignored per
["any properties added SHALL be
ignored"](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#reference-object)
() This was a problem for me since I want to use a reference to an enum
as a header parameter in FastAPI. The OpenAPI document generated by
FastAPI included several fields (title, description, etc) along with
`$ref`. The`Schema` instance it was validate to lacked any actual type
constraint information, so openapi-python-client needed to treat this as
an `AnyParameter`, and disallowed it in headers.
I have attached an example OpenAPI document
[`oa.json`](https://github.com/user-attachments/files/19170207/oa.json)
you can use to replicate this with the current `openapi-python-client`,
or you can use the test cases from the first commit in this PR, which
resolves it by using a Pydantic discriminated union testing for the
presence of `$ref` for all the unions including `Reference`.
(I had created an [issue
upstream](kuimono/openapi-schema-pydantic#36),
but figured I'd share the workaround here.)
---------
Co-authored-by: Natarajan Krishnaswami <[email protected]>
Co-authored-by: Dylan Anthony <[email protected]>
0 commit comments