fix: include additionalProperties in schema traversal for model_rebuild#438
Conversation
_get_combined_attributes omitted additionalProperties, so inline schemas
used as map value types (e.g. nullable+allOf+$ref) were never registered
in the types dict and never had model_rebuild called. This left generated
Pydantic models with unresolved ForwardRefs (__pydantic_complete__=False).
Fixes the case:
additionalProperties:
nullable: true
allOf:
- $ref: '#/components/schemas/SomeModel'
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #438 +/- ##
==========================================
+ Coverage 93.89% 93.90% +0.01%
==========================================
Files 104 104
Lines 8397 8414 +17
==========================================
+ Hits 7884 7901 +17
Misses 513 513
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I can produce a test for this too, but copilot placed the reference schema in tests/fixtures, and by the README.md I'm not sure this is a good idea. I will push it to the branch as a new commit (Sorry for ghosting you when I last worked with this codebase; I got pulled to something else after that summer. Should have replied once I realised I had left you hanging) |
nullable additionalProperties have to be RootModels
add test for implicit/explicit nullable & oneOf
|
Hi, types with multiple identities (here: object|null) have to be RootModels, else there is inconsistent behavior. This changes the access to the model - using .root on the model. I added the missing bits to make this happen. Don't worry about the PR interaction in 2023, to me everything was fine. |
|
Awesome, thank you! |
_get_combined_attributes omitted additionalProperties, so inline schemas used as map value types (e.g. nullable+allOf+$ref) were never registered in the types dict and never had model_rebuild called. This left generated Pydantic models with unresolved ForwardRefs (pydantic_complete=False).
Fixes the case:
additionalProperties:
nullable: true
allOf:
- $ref: '#/components/schemas/SomeModel'