Skip to content

Remove the duplicated code of the first part of parser/jsonschema.py: one type intersection core, one tuple position path and dynamic anchor components from _scc - #5511

Merged
Koudai Aono (koxudaxi) merged 23 commits into
dry-r19from
dry-r23
Oct 29, 2026
Merged

Koudai Aono (koxudaxi) merged 23 commits into
dry-r19from
dry-r23

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved JSON Schema handling for references that use escaped paths or array indices, including optional references to missing values.
    • Improved parsing of recursive dynamic references and schema combinations.
    • Request and response model variants now better reflect read-only and write-only fields.
    • Updated handling of array items, inherited schemas, and additional properties for generated models.

… experimental registries through one shared Markdown renderer
… instead of the seven flags written out at each site
…on, one literal container renderer and smaller copies
… table, one protobuf declaration walk, Avro defaults read from the logical type ladder and smaller copies
… one type intersection core, one tuple position path, dynamic anchor components from _scc and smaller copies
# Conflicts:
#	src/datamodel_code_generator/_parser_context.py
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 5bbc27d and 43e5190.

Files ignored due to path filters: 1
  • tests/data/expected/parser/schema_runtime_unique_items_branch_coverage.snapshot is excluded by none and included by none
Files selected for processing: 5
  • scripts/decision_homes.toml
  • src/datamodel_code_generator/parser/_intersection.py
  • src/datamodel_code_generator/parser/jsonschema.py
  • tests/assert_helper_allowlists.py
  • tests/parser/test_jsonschema.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

Walkthrough

The JSON Schema parser now uses shared type, constraint, reference, and model-variant helpers. It also updates array and inherited-schema handling and computes dynamic-anchor usage through reachable-node graphs and strongly connected components.

Changes: JSON Schema parsing and merging

Layer / File(s) Summary
Shared type and intersection handling
src/datamodel_code_generator/parser/_intersection.py, src/datamodel_code_generator/parser/jsonschema.py, tests/parser/test_jsonschema.py, tests/assert_helper_allowlists.py
The parser exposes shared type and intersection helpers and uses them in schema merging and constraint processing. The test imports and coverage snapshot no longer include two private helper checks.
Reference traversal and lookup
src/datamodel_code_generator/parser/jsonschema.py
Decoded JSON Pointer traversal supports missing-value checks. Reference lookup, external-reference key normalization, and reference-fact caching use shared helpers.
Schema constraints and array handling
src/datamodel_code_generator/parser/jsonschema.py
Constraint extraction and array-position selection use shared helpers. The parser also updates exclusive-bound conversion, property-count handling, and tuple inference.
Inherited fields and read/write variants
src/datamodel_code_generator/parser/jsonschema.py
Inherited-field handling and read/write fact aggregation are consolidated. Additional-property types are stored through a shared helper for model variants.
Dynamic-anchor reachability
src/datamodel_code_generator/parser/jsonschema.py, scripts/decision_homes.toml
Dynamic-reference analysis builds a reachable-node graph, computes strongly connected components, and caches anchor usage. The H20 adapter list includes _dynamic_anchors_used.

Priority: Low

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Refactor

Possibly related issues

  • Issue 5453 — The changes consolidate type intersection used during JSON Schema merging, which is related to the issue’s nested-property intersection behavior.
  • Issue 5380 — The changes update shared intersection and $ref sibling analysis in the parser area identified by this issue.

Possibly related PRs

Merge Risk: Minimal · up to 43e51

The parser consolidation has no identified merge-blocking issue and appears mergeable subject to normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title accurately describes the main changes: deduplicating type intersection logic, tuple position paths, and dynamic anchor handling. It is lengthy, but it remains specific and related to the cha…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title accurately describes the main changes: deduplicating type intersection logic, tuple position paths, and dynamic anchor handling. It is lengthy, but it remains specific and related to the changeset.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. 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 4 functions across 1 files. (2 skipped: 1 unsupported, 1 too large.)

Finishing Touches: 💡 1
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T10:48:44.049230Z 43e5190 PR opened
ℹ️ About Codex in GitHub

Your 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.

@github-actions

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Oct 29, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 31.04%

2 warnings

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

❌ 52 regressed benchmarks
⏩ 98 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_perf_client_calls[sync] 23.8 ms 42.1 ms -43.43%
❌ test_perf_client_calls[async] 26.9 ms 46.8 ms -42.46%
❌ test_perf_simple_msgspec_unset_field_rendering 300.8 ms 520 ms -42.15%
❌ test_perf_load_pyproject_config[mapping-None] 231.6 µs 369.9 µs -37.39%
❌ test_perf_scalar_root_collapsed_builtin 128 ms 202.9 ms -36.89%
❌ test_perf_large_models_msgspec 1.2 s 1.9 s -36.58%
❌ test_perf_load_pyproject_config[config-multiple] 240.1 µs 378.5 µs -36.56%
❌ test_perf_load_pyproject_config[config-None] 229.5 µs 361.3 µs -36.49%
❌ test_perf_large_models_typed_dict[total-false-requiredness] 715.2 ms 1,123.8 ms -36.36%
❌ test_perf_load_pyproject_config[mapping-multiple] 239.9 µs 375 µs -36.03%
❌ test_perf_local_reference_file_resolution 80.4 ms 125.3 ms -35.82%
❌ test_perf_large_models_dataclass_builtin 875.4 ms 1,331.1 ms -34.23%
❌ test_perf_large_models_typed_dict[legacy-requiredness] 720.7 ms 1,094.9 ms -34.18%
❌ test_perf_multiple_files_input 2.6 s 3.9 s -33.9%
❌ test_perf_all_options_enabled 4.1 s 6.2 s -33.81%
❌ test_perf_ordinary_array_constraint_generation 1.2 s 1.8 s -33.6%
❌ test_perf_large_models_single_module_stdout 958.2 ms 1,441.1 ms -33.5%
❌ test_perf_false_reference_validation 167.9 ms 250.6 ms -32.99%
❌ test_perf_large_models_pydantic_v2_noformat 800.6 ms 1,194.2 ms -32.96%
❌ test_perf_deep_nested 3.8 s 5.7 s -32.92%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing dry-r23 (43e5190) with dry-r19 (5bbc27d)

Open in CodSpeed

Footnotes

  1. 98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@koxudaxi
Koudai Aono (koxudaxi) merged commit 9ce7a57 into main Oct 29, 2026
163 of 164 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the dry-r23 branch October 29, 2026 11:56
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR is an internal refactor of the JSON Schema parser that keeps behaviour the same. In the private parser/_intersection.py module, _types and _intersect_types are renamed to declared_types and intersect_types and a common_types helper is added. In jsonschema.py, private helpers that duplicated these are removed and replaced: _json_schema_types, _intersect_json_schema_types, _admits_arrays, _json_literal_may_accept_container, _json_schema_type_may_accept_container, _get_model_by_path_or_missing and _get_data_type_constraint_kwargs. Private parser methods are folded into shared ones: _get_schemas_before_false, _tail_schema, _get_explicit_fixed_positional_items, _get_fixed_length_prefix_tuple_items, _fallback_array_item_data_types and _finalize_required_inherited_field. The hand-written Tarjan SCC is replaced with the shared strongly_connected_components helper. Several match blocks and boolean chains are collapsed into equivalent expressions: the exclusive bound validator, the property-count constraints, propertyNames checks, read/write variant facts, external ref mapping keys and constraint value collection. Every removed or renamed symbol is underscore-private. The constraint_fields class attribute still holds the same set. No CLI option, public Python API, template or Python version support changes. The only test changes delete assertions on the removed private helpers, and no expected generated-output fixtures change, so the generated code is the same as at the parent commit. The behaviour-gate rows marked accepted compare against the last release and describe an earlier allOf change; their notes name a different PR and none of their fixtures change here. The other rows are both-fail or crash-fix, which do not change behaviour.


This analysis was produced by the release draft workflow

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🎉 Released in 0.88.0

This PR is now available in the latest release. See the release notes for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant