Skip to content

Choose the parse method for every schema position from one table - #5158

Merged
Koudai Aono (koxudaxi) merged 1 commit into
gr12-render-memosfrom
fe7a-parse-table
Oct 23, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
gr12-render-memosfrom
fe7a-parse-table

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of composed OpenAPI request-body schemas, including allOf and oneOf schemas with object properties.
    • Ensured JSON Schema objects with properties are still parsed when oneOf member types are unavailable.
    • Added support for generating query parameter models when a parameter has no name.
  • Documentation
    • Updated architecture and development guidance for schema parsing and schema-graph checks.

@coderabbitai

coderabbitai Bot commented Oct 22, 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 f805a47 and 0bb237b.

⛔ Files ignored due to path filters: 10
  • docs/llms-full.txt is excluded by none and included by none
  • tests/data/expected/architecture_boundaries/classifications.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/jsonschema/main_jsonschema/one_of_without_member_types_beside_properties.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/jsonschema/main_jsonschema/schema_graph_check_of_a_dispatch_that_takes_another_row[off].txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/jsonschema/main_jsonschema/schema_graph_check_of_a_dispatch_that_takes_another_row[report].report.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/openapi/main_openapi/one_of_body_without_member_types_beside_properties.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/jsonschema/one_of_beside_properties.json is excluded by !tests/data/**/*.json and included by none
  • tests/data/openapi/all_of_request_body.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/openapi/one_of_body_beside_properties.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/openapi/parameter_without_name.yaml is excluded by !tests/data/**/*.yaml and included by none
📒 Files selected for processing: 16
  • docs/architecture.md
  • docs/development-contributing.md
  • scripts/check_architecture_boundaries.py
  • src/datamodel_code_generator/_checks.py
  • src/datamodel_code_generator/parser/_schema_dispatch.py
  • src/datamodel_code_generator/parser/jsonschema.py
  • src/datamodel_code_generator/parser/openapi.py
  • tests/data/expected/main/openapi/main_openapi/all_of_request_body.py
  • tests/data/expected/main/openapi/parameter_without_name.py
  • tests/main/jsonschema/test_main_jsonschema.py
  • tests/main/jsonschema/test_main_jsonschema.refs
  • tests/main/openapi/test_main_openapi.py
  • tests/main/openapi/test_main_openapi.refs
  • tests/main/test_payload_validation.refs
  • tests/test_architecture_boundaries.py
  • tests/test_yaml_fast_constructor.refs

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

📝 Walkthrough

The parser now selects schema-building paths through ordered dispatch tables for definition, field, and OpenAPI operation positions. Schema-graph checks compare table selections with legacy paths. Tests and generated-output references cover dispatch cases and OpenAPI schemas.

Changes: Schema-position dispatch

Layer / File(s) Summary
Shared dispatch model
src/datamodel_code_generator/parser/_schema_dispatch.py, docs/architecture.md, scripts/check_architecture_boundaries.py, tests/test_architecture_boundaries.py
Adds dispatch types for schema positions, sites, ordered steps and rows, defaults, and choices. The architecture description and boundary classification include the new module.
JSON Schema dispatch
src/datamodel_code_generator/parser/jsonschema.py, src/datamodel_code_generator/_checks.py, docs/development-contributing.md, tests/main/jsonschema/*
Routes field and definition parsing through ordered tables. Schema-graph checks compare selected rows with legacy paths. Tests cover mismatches and schemas with properties but no parsed oneOf member types.
OpenAPI operation dispatch
src/datamodel_code_generator/parser/openapi.py, tests/main/openapi/*, tests/main/test_payload_validation.refs, tests/data/expected/main/openapi/*, tests/test_yaml_fast_constructor.refs
Routes operation schemas through an ordered table. Tests and generated-output references cover composed request bodies, missing oneOf member types, and query parameters without names.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Possibly related issues

  • datamodel-code-generator issue 5155: The dispatch table distinguishes schema positions, including OpenAPI operation schemas, but the supplied changes do not state that request and response handling now differs.
  • datamodel-code-generator issue 4496: The JSON Schema field table includes typed nullable-map handling, but the supplied changes do not establish a correction for typed map request bodies.
  • datamodel-code-generator issue 4820: The tables define ordered handling for composition schemas, but the supplied changes do not establish a change to the reported allOf precedence behavior.
  • datamodel-code-generator issue 4854: The field dispatch covers composition schemas, but the supplied changes do not establish a correction for inline primitive allOf properties.
Merge Risk: ⚪ Minimal · up to 0bb23

This change moves schema parse-method selection into ordered tables while preserving the previous branch precedence. No concrete behavior regression was found, so it looks safe to merge after normal checks.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 7 files. (9 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: selecting parse methods for all schema positions through one dispatch table.
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: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 7 files. (9 skipped: 6 unsupported, 3 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches: 💡 2
📝 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 22, 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-22T18:18:35.157599Z 0bb237b 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 22, 2026

Copy link
Copy Markdown

Merging this PR will regress 1 benchmark

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

⚡ 48 improved benchmarks
❌ 1 regressed benchmark
✅ 1 untouched benchmark
⏩ 98 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_perf_false_reference_validation 278.9 ms 383.7 ms -27.32%
⚡ test_perf_pydantic_field_name_resolution 2,052.4 µs 959.7 µs ×2.1
⚡ test_perf_client_calls[async] 37.3 ms 19.7 ms +89.53%
⚡ test_perf_client_calls[sync] 34 ms 18.2 ms +86.57%
⚡ test_perf_simple_msgspec_unset_field_rendering 157.4 ms 85.7 ms +83.58%
⚡ test_perf_load_yaml_openapi_large 36.6 ms 20.1 ms +82.3%
⚡ test_perf_unique_items_runtime_scalar_validation 2.9 ms 1.6 ms +81.05%
⚡ test_perf_unique_items_nested_model_validation 3 ms 1.7 ms +79.67%
⚡ test_perf_graphql_style_pydantic_v2 792.1 ms 453.3 ms +74.73%
⚡ test_perf_duplicate_names 977.3 ms 564.8 ms +73.04%
⚡ test_perf_extreme_large_schema 14.4 s 8.4 s +71.4%
⚡ test_perf_load_pyproject_config[config-multiple] 302.1 µs 176.3 µs +71.32%
⚡ test_perf_load_pyproject_config[config-None] 290.2 µs 171 µs +69.68%
⚡ test_perf_kubernetes_style_pydantic_v2 2.4 s 1.4 s +68.82%
⚡ test_perf_large_models_pydantic_v2 3.3 s 2 s +68.32%
⚡ test_perf_load_pyproject_config[mapping-multiple] 298.1 µs 177.3 µs +68.16%
⚡ test_perf_empty_pydantic_v2_field_render_plans 40.8 ms 24.3 ms +68.03%
⚡ test_perf_large_models_typed_dict[total-false-requiredness] 1,133.5 ms 678.7 ms +67%
⚡ test_perf_load_pyproject_config[mapping-None] 293.8 µs 176.6 µs +66.44%
⚡ test_perf_stripe_style_pydantic_v2 2 s 1.2 s +66.23%
... ... ... ... ...

ℹ️ 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 fe7a-parse-table (0bb237b) with main (781932d)2

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

  2. No successful run was found on gr12-render-memos (f805a47) during the generation of this report, so main (781932d) was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Oct 22, 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 c0a62d0 into main Oct 23, 2026
131 of 132 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the fe7a-parse-table branch October 23, 2026 02:20
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR is an internal refactor of how the parser dispatches schema objects. It adds a private module, parser/_schema_dispatch.py, with ordered dispatch tables for three schema positions: definition, field and OpenAPI operation. It then rewrites the private methods _parse_schema_obj, _parse_schema_item_shape and _parse_object_kind_schema, plus OpenAPIParser.parse_schema, so each looks up its parse method in one of these tables. The tables check the same conditions in the same order as the old if/elif chains. The rows still call the public hooks (parse_array, parse_all_of, parse_one_of, parse_any_of, parse_object, parse_enum, parse_root_type, parse_ref, get_data_type) through the parser, so subclasses that override those hooks keep working. Public method signatures are unchanged. _parse_constrained_type_union is kept and now delegates to two new helpers with equivalent logic. No CLI options, config fields, templates, defaults or Python version support change. The only new runtime behavior is an extra violation of kind dispatch under the opt-in DATAMODEL_CODE_GENERATOR_CHECK_SCHEMA_GRAPH developer check, which compares each table choice with the old dispatch. The new test fixtures (an allOf request body, a oneOf body beside properties, a parameter without a name) cover branches that were previously marked no cover. They do not show any change to generated output. The remaining changes are documentation and the architecture-boundary list, so nothing here breaks existing users.


This analysis was produced by the release draft workflow

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