-
Notifications
You must be signed in to change notification settings - Fork 10
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
fix: replace invalid characters in $ref field with underscore. #50
base: main
Are you sure you want to change the base?
Conversation
Thanks @jfschneider! Would you mind adding a comment explaining the logic too, and a link to the pydantic source? Would also be great if you could add a test or two to cover this case 🙏🏼 |
Hi, sure, I can provide a link and an explanation. I also just noticed that there is a duplicate of the util.py in the v3_0 folder, so I probably should duplicate the fix there, too, and then put the tests in tests/util/test_utily.py and tests/v3_0/test_utily.py? |
OK, that was a bit premature. I had a test that works, but just for either pydantic v2 orv1 (basically copied a test in util.py and just used a generic as response), not v1, which seems to use a different method for generic models: |
Yep exactly that, you can use the PYDANTIC_V2 flag to constrain certain tests to pydantic V1 or v2 if that helps seperate concerns/fixtures like here |
Sooo, after a lot of trial and error, I managed to cobble up full tests for pydantic v1/v2. The tox run still fails, but not in my tests ("tests/util/test_pydantic_field.py:72: AssertionError"), and that also fails in a clean clone of the original repo, so I gather it has nothing to do with my changes... I briefly thought about fixing the _construct_ref_obj function by instantiating the Pydantic GenerateJSONschema-class and calling the normalize_name-method, but decided against it as those classes are again different in Pydantic V1/V2 which would've required some further if-else and bloated code, so I just copied the regex from the normalize_name method, as I think it is rather unlikely to change often. It just replaces invalid characters for refnames with an underscore. |
Ah yes, looks like the break was introduced in a recent Pydantic update (pydantic/pydantic#10692) - i'll address this separately 👍🏼 Could you add the comment with source/explanation however for the regex logic? 🙏🏼 |
Test is fixed in #52 - if you rebase to main you should pick it up 👍🏼 |
Do you mean add a comment in the function itself? |
Yep exactly, something inline by the regex to explain it a bit for future readers
…________________________________
From: jfschneider ***@***.***>
Sent: Tuesday, December 3, 2024 11:40:14 AM
To: mike-oakley/openapi-pydantic ***@***.***>
Cc: Mike Oakley ***@***.***>; Comment ***@***.***>
Subject: Re: [mike-oakley/openapi-pydantic] fix: replace invalid characters in $ref field with underscore. (PR #50)
Ah yes, looks like the break was introduced in a recent Pydantic update (pydantic/pydantic#10692<pydantic/pydantic#10692>) - i'll address this separately 👍🏼
Could you add the comment with source/explanation however for the regex logic? 🙏🏼
Do you mean add a comment in the function itself?
—
Reply to this email directly, view it on GitHub<#50 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AENE36D3U6XQEIESHW4BIET2DWDA5AVCNFSM6AAAAABRNCDE6OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMJUGE3TQMRVGI>.
You are receiving this because you commented.Message ID: ***@***.***>
|
9575fa7
to
143d088
Compare
OK, added a docstring with an explanation. Tests were fine now. |
used the regex from pydantic.json_schema.GenerateJSONSchema.normalize_name to replace all characters that are invalid reference names.