Repository navigation
Generate request-response models of dataclass, msgspec and TypedDict where additionalProperties sit beside properties - #5243
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d40af8f4f0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
Merging this PR will degrade performance by 31.57%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…where additionalProperties sit beside properties Under --read-only-write-only-model-type request-response the schema graph read the additionalProperties beside properties as a reference of the model, which holds for pydantic v2 BaseModel, whose typed extra field names their type. A dataclass, a pydantic dataclass, a msgspec Struct and a TypedDict under --no-use-closed-typed-dict accept extra keys of any type, so such a model did not split while the references to it read variants that were never generated, and generation failed with "A Parser can not resolve classes". The graph now reads those additionalProperties only where the model writes their type, also where the properties come from the $ref beside them: the other models keep one class, as without the option, and only the readOnly model splits. A TypedDict writes their type as extra_items, which named the readOnly model while its model did not split. Such a model now splits where the type it writes as extra_items names a model with variants, and each variant names the matching variant there. Fixes: #5209
d40af8f to
8485884
Compare
Breaking Change AnalysisResult: No breaking changes detected Reasoning: This is a narrow bug fix to the opt-in request-response read-only/write-only model splitting in the JSON Schema parser. It only matters when a model has both properties and a schema-valued additionalProperties that points to a model with readOnly or writeOnly fields. The parser now uses the additionalProperties type to decide the split only for output types that actually write that type: pydantic v2 BaseModel through its typed extra field, and TypedDict through extra_items when closed TypedDicts are enabled. For those, the holder model now splits into Request and Response variants, so its extras point to the matching variant instead of to a base model that is never generated in request-response mode. For dataclass, pydantic dataclass, msgspec and open TypedDict output, additionalProperties beside properties no longer count as a type reference, because those models accept extra keys of any type. This keeps the predicted split and the generated split consistent. The same handling now also covers additionalProperties placed beside a $ref. Before this change, this schema pattern gave inconsistent or invalid output, so the new behavior corrects broken output rather than changing working output. The diff adds only new test fixtures and expected outputs, and no existing expected output was modified. No CLI options, public Python APIs, defaults, templates or supported Python versions change. The only signature changes are to private underscore-prefixed parser helpers, namely _splits_into_rw_model_variants, which now takes a reference, and _iter_rw_model_schema_children, which now takes a types_extras keyword. These are internal and not part of the public API. This analysis was produced by the release draft workflow |
Fixes: #5209
Summary by CodeRabbit