Repository navigation
Write an allOf whose parts admit no object as the intersection of its parts instead of a model without fields - #5406
Conversation
… parts instead of a model without fields
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. |
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
| Layer / File(s) | Summary |
|---|---|
Convert eligible allOf schemas to value models src/datamodel_code_generator/parser/jsonschema.py, docs/cli-reference/typing-customization.md, tests/data/expected/main/jsonschema/*, tests/data/expected/main/openapi/*, tests/data/expected/main/schema_intersection_shapes/... |
The parser now checks whether an intersected type excludes objects when the option is off. The documentation and expected outputs show scalar and array root models with constraints. |
Add scalar-reference output coverage tests/data/expected/main/schema_intersection_shapes/schema_intersection_shape_output* |
Expected outputs add scalar and collection aliases, constraints, and aggregate model fields across model configurations, both with and without the option. |
Align constrained-reference fixtures and test mappings tests/data/expected/main/schema_intersection_shapes/schema_intersection_shape_output*, tests/main/*.refs |
Expected-output snapshots and test references change for constrained references, allOf cases, root-site nullability, and root-value schemas. |
Priority:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)
sequenceDiagram
participant JsonSchemaInput
participant JsonSchemaParser
participant GeneratedModelOutput
JsonSchemaInput->>JsonSchemaParser: Supply allOf schema
JsonSchemaParser->>GeneratedModelOutput: Convert eligible non-object intersection to value schema
Possibly related issues
- Issue 5385: The changes cover scalar
allOfintersections, which is the area described in this issue. - Issue 4765: The parser change addresses scalar
allOfconstraint handling, though the supplied context does not establish coverage of every single-reference case. - Issue 4858: The parser change covers scalar
allOfhandling, but the supplied context does not establish that enum intersections are resolved.
Suggested labels: breaking-change-analyzed
Merge Risk: 
Minimal · previous review ebd82
-
The change makes eligible scalar allOf intersections generate value types rather than empty object models. No concrete merge-blocking issue is established by the supplied evidence.
Pre-merge checks: 
5
-
Full details: Linked Issues check
-
Explanation
Issue
#5401requires integer handling forallOfitem andadditionalPropertiesschemas that combine integer$refs with constraints.src/datamodel_code_generator/parser/jsonschema.pynow converts anallOfvalue schema when the intersection excludes objects. The updated Pydantic v2 expected output forallof_ref_item_constraintsuses constrained integer types withge=4andle=5fortwo_itemsandtwo_map, instead of emptyBaseModelclasses. The test reference files include these updated cases. This covers the required implementation and automated regression coverage.
Full details: Out of Scope Changes check
-
Explanation
The changed source logic generalizes
allOfconversion for schemas that cannot represent objects. The updated fixtures cover related scalar, array, reference, constraint, and root-form cases across supported output types. The documentation and expected-output changes describe or test this sameallOfroot-value behavior. The summary provides no demonstrated unrelated product change.
Full details: Docstring Coverage
-
Explanation
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 49 files. (7 skipped: 3 unsupported, 1 too large, 3 over the file limit.)
-
Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Merging this PR will degrade performance by 46.44%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
…s under --collapse-root-models and its regex engine to itself
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
… would need the regex engine of the models using its type alias
…nd allof_scalar_roots in the behaviour diff allowlist
…-items # Conflicts: # scripts/behaviour_diff_allowlist.toml
# Conflicts: # tests/parser/test_generation_store_usage.py
…ies and covering their directory input and validation probes
…yOf member, and accept the default rules its fields now take in the behaviour diff allowlist
# Conflicts: # scripts/behaviour_diff_allowlist.toml
Breaking Change AnalysisResult: Breaking changes detected Reasoning: The PR changes default output for JSON Schema and OpenAPI allOf sites whose intersected parts admit no object. Before, without the intersect allOf keywords option, these were written as empty models that rejected every valid value. They are now written as the constrained value type: RootModel for Pydantic v2 and type aliases for dataclasses, msgspec and TypedDict. The behaviour diff gate marks these cells as accepted, meaning default output changed for allof_root_model_constraints, allof_scalar_roots, the schema_intersection directories and allof_scalar_refs. The changes include model kind changes, changed field types, models no longer emitted under collapse-root-models, added regex_engine config and compile imports for lookaround patterns, and inverted validation results. With strip-default-none or the default-factory option, affected fields also get different defaults and constructor order. No CLI options, public API, templates or Python versions are removed or changed. The only API change adds two ClassVar hooks to DataModelFieldBase that default to None. The one changed error expectation drops a parameter error that no longer happens because an allOf of scalars now resolves to a scalar kind, so it fixes a spurious error rather than breaking anything. Content for Release NotesCode Generation Changes
This analysis was produced by the release draft workflow |
|
🎉 Released in 0.88.0 This PR is now available in the latest release. See the release notes for details. |
Fixes: #5401
Summary by CodeRabbit
allOfschemas, including minimum item counts and combined patterns.