-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
avoid misparsing references as other types using Pydantic discriminated unions #1216
avoid misparsing references as other types using Pydantic discriminated unions #1216
Conversation
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.
I think your read of the spec is right, the presence of $ref
should guarantee it's treated like a reference. Thanks for the fix!
A couple recommendations:
- Taking prints out of the tests, I assume those were there for debugging
- We should add an e2e test for this as well, just to make sure if we tweak the way we use models at some point we don't get a regression. I think just adding some extra stuff to existing
$ref
s in https://github.com/openapi-generators/openapi-python-client/blob/main/end_to_end_tests/baseline_openapi_3.0.json and verifying it doesn't change anything should be enough.
Thanks, @dbanty -- I'll make the updates now. |
* Remove `print` statements * add example verifying new behavior to E2E test
I've confirmed the modified E2E test fails without this change, also |
@nkrishnaswami hope you don't mind I pushed directly to try and solve mypy & Ruff's complaints in CI |
Don't mind at all -- thanks! |
I’ve found a corner case, I think due to changes to Pydantic’s smart mode for disambiguating unions, where a subdocument with a
$ref
key and additional keys (title, description, etc) is validated as aSchema
instead of as aReference
model. I believe these should be ignored per "any properties added SHALL be ignored" () 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
. TheSchema
instance it was validate to lacked any actual type constraint information, so openapi-python-client needed to treat this as anAnyParameter
, and disallowed it in headers.I have attached an example OpenAPI document
oa.json
you can use to replicate this with the currentopenapi-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 includingReference
.(I had created an issue upstream, but figured I'd share the workaround here.)