Skip to content

Merge four opt-in options into --order-constructor-fields-by and --openapi-as-definitions - #5330

Merged
Koudai Aono (koxudaxi) merged 1 commit into
fix-5273-msgspec-annotated-nonefrom
opt-consolidate-d1
Oct 26, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
fix-5273-msgspec-annotated-nonefrom
opt-consolidate-d1

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Added consolidated options for selecting OpenAPI definitions and constructor field ordering, with selectable modes for each.
    • Preset and configuration examples now show how to set these options, including how an empty list overrides preset values.
  • Documentation
    • Updated the CLI reference, quick reference, FAQ, and architecture guide to reflect the revised option syntax and behavior.
  • Compatibility
    • Replaced the previous individual flags with the consolidated options; update existing CLI commands and configuration files accordingly.

…enapi-as-definitions

The four unreleased opt-in options of 0.87.0 that share a principle become values of two
multi-value options, like --deserialize-default-values. Each value is still its own change,
and generated output is the same as with the old spellings.

Old -> new spellings:
- --order-constructor-fields-by-final-names -> --order-constructor-fields-by final-names
- --order-constructor-fields-by-written-defaults -> --order-constructor-fields-by written-defaults
- --openapi-paths-bodies-as-definitions -> --openapi-as-definitions paths-bodies
- --openapi-ref-components-as-definitions -> --openapi-as-definitions ref-components
- pyproject.toml: order-constructor-fields-by-final-names / -written-defaults = true ->
  order-constructor-fields-by = ["final-names", "written-defaults"];
  openapi-paths-bodies-as-definitions / openapi-ref-components-as-definitions = true ->
  openapi-as-definitions = ["paths-bodies", "ref-components"]; an empty list turns off
  the values a preset sets
- Python API: order_constructor_fields_by_final_names / order_constructor_fields_by_written_defaults
  (bool) -> order_constructor_fields_by: Sequence[ConstructorFieldOrder];
  openapi_paths_bodies_as_definitions / openapi_ref_components_as_definitions (bool) ->
  openapi_as_definitions: Sequence[OpenAPIAsDefinitions]

The 20261019 presets set both values of each option in one group, and the
openapi.paths-bodies-as-definitions recommender rule recommends both as-definitions values.
@coderabbitai

coderabbitai Bot commented Oct 24, 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 fae3a38 and 0a01f85.

Files ignored due to path filters: 17
  • docs/llms-full.txt is excluded by none and included by none
  • skills/datamodel-code-generator/references/cli-options.md is excluded by none and included by none
  • src/datamodel_code_generator/resources/recommender_rules.json is excluded by none and included by none
  • tests/data/expected/builtin_formatter/parser_config_contract.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/help/color.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/help/no_color.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/recommend_options/paths_bodies.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/recommend_options/paths_bodies_included.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/recommend_options/paths_bodies_path_item_ref.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main_kr/generate_prompt/basic.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main_kr/generate_prompt/json_output.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main_kr/generate_prompt/with_list_options.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main_kr/generate_prompt/with_options.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main_kr/generate_prompt/with_question.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/preset_docs/presets_json.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/preset_docs/presets_markdown.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/prompt/default_parser_text.txt is excluded by !tests/data/**/*.txt and included by none
Files selected for processing: 38
  • docs/architecture.md
  • docs/cli-reference/index.md
  • docs/cli-reference/model-customization.md
  • docs/cli-reference/openapi-only-options.md
  • docs/cli-reference/quick-reference.md
  • docs/cli-reference/topics/openapi.md
  • docs/faq.md
  • docs/presets.md
  • src/datamodel_code_generator/__init__.py
  • src/datamodel_code_generator/_parse_memo.py
  • src/datamodel_code_generator/_recommend/_signals.py
  • src/datamodel_code_generator/_types/generate_config_dict.py
  • src/datamodel_code_generator/_types/parser_config_dicts.py
  • src/datamodel_code_generator/arguments.py
  • src/datamodel_code_generator/base_config.py
  • src/datamodel_code_generator/cli_options.py
  • src/datamodel_code_generator/config.py
  • src/datamodel_code_generator/enums.py
  • src/datamodel_code_generator/model/_decisions/assignment.py
  • src/datamodel_code_generator/model/base.py
  • src/datamodel_code_generator/model/msgspec.py
  • src/datamodel_code_generator/parser/_finality.py
  • src/datamodel_code_generator/parser/_pass_decls.py
  • src/datamodel_code_generator/parser/_passes/render_prep.py
  • src/datamodel_code_generator/parser/base.py
  • src/datamodel_code_generator/parser/openapi.py
  • src/datamodel_code_generator/preset.py
  • src/datamodel_code_generator/prompt_data.py
  • tests/data/expected/main/input_model/config_class.py
  • tests/data/expected/main/preset_opt_in_options/option_list_in_pyproject[empty-list-under-preset].py
  • tests/main/jsonschema/test_main_jsonschema.py
  • tests/main/jsonschema/test_object_maps.py
  • tests/main/openapi/test_inherited_keyword_only_copies.py
  • tests/main/openapi/test_main_openapi.py
  • tests/main/test_preset_opt_in_options.py
  • tests/main/test_preset_opt_in_options.refs
  • tests/main/test_public_api_signature_baseline.py
  • tests/parser/test_pipeline.py

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

Walkthrough

The CLI and configuration replace two pairs of boolean options with enum-backed list options for constructor-field ordering and OpenAPI definition selection. Parser handling, preset values, tests, public signatures, and documentation use the consolidated options.

Changes: Option consolidation

Layer / File(s) Summary
Option types and configuration contract
src/datamodel_code_generator/enums.py, src/datamodel_code_generator/arguments.py, src/datamodel_code_generator/config.py, src/datamodel_code_generator/base_config.py, src/datamodel_code_generator/_types/*, src/datamodel_code_generator/cli_options.py, src/datamodel_code_generator/__init__.py, tests/main/test_public_api_signature_baseline.py, tests/data/expected/main/input_model/config_class.py
Adds ConstructorFieldOrder and OpenAPIAsDefinitions. Replaces the related boolean configuration fields with sequence-valued fields and updates CLI options and public signature baselines.
Parser selection and preset values
src/datamodel_code_generator/parser/base.py, src/datamodel_code_generator/parser/openapi.py, src/datamodel_code_generator/__init__.py, src/datamodel_code_generator/preset.py, tests/main/test_preset_opt_in_options.py, tests/main/test_preset_opt_in_options.refs, tests/data/expected/main/preset_opt_in_options/*
Parser selection checks the new enum values. Presets set list-valued options, and tests compare TOML list configuration with equivalent CLI arguments, including an empty list under a preset.
Documentation and option test updates
docs/*, src/datamodel_code_generator/_parse_memo.py, src/datamodel_code_generator/_recommend/_signals.py, src/datamodel_code_generator/model/*, src/datamodel_code_generator/parser/_finality.py, src/datamodel_code_generator/parser/_pass_decls.py, src/datamodel_code_generator/parser/_passes/render_prep.py, tests/main/jsonschema/*, tests/main/openapi/*, tests/parser/test_pipeline.py
Updates option references and examples. Existing tests use the consolidated option names and values for constructor ordering and OpenAPI definition modes.

Priority: Low

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

Change: Refactor

Possibly related issues

Possibly related PRs

Suggested labels: breaking-change

Merge Risk: Minimal · up to 0a01f

The consolidated options appear mergeable after normal checks; the inspected configuration paths retain their independent behaviors.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 27 files. (11 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: consolidating four opt-in options into the two grouped options --order-constructor-fields-by and --openapi-as-definitions.
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 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 27 files. (11 skipped: 9 unsupported, 2 too large.)

Resolution

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

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
  • 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 24, 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-24T20:08:52.012316Z 0a01f85 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 24, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 18.03%

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

❌ 41 regressed benchmarks
✅ 9 untouched benchmarks
⏩ 98 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_perf_recommend_options_full_kubernetes_style 16.7 s 23.7 s -29.59%
❌ test_perf_target_render[fastapi-large] 5.6 s 7.4 s -24.93%
❌ test_perf_load_pyproject_config[mapping-None] 288.8 µs 374.3 µs -22.84%
❌ test_perf_false_reference_validation 314.8 ms 407.7 ms -22.78%
❌ test_perf_load_pyproject_config[config-None] 285.8 µs 369.6 µs -22.68%
❌ test_perf_load_pyproject_config[mapping-multiple] 296.9 µs 382.5 µs -22.37%
❌ test_perf_load_pyproject_config[config-multiple] 298.3 µs 383.6 µs -22.23%
❌ test_perf_deep_nested 5.3 s 6.7 s -21.58%
❌ test_perf_client_calls[async] 36.9 ms 47.1 ms -21.55%
❌ test_perf_client_calls[sync] 33.5 ms 42.4 ms -20.91%
❌ test_perf_target_render[client-large] 6.7 s 8.4 s -20.89%
❌ test_perf_local_reference_file_resolution 157.5 ms 196 ms -19.62%
❌ test_perf_complex_refs 2.1 s 2.6 s -19.09%
❌ test_perf_all_options_enabled 6 s 7.5 s -19.02%
❌ test_perf_large_models_pydantic_v2 3.5 s 4.3 s -18.66%
❌ test_perf_extreme_large_schema 14.9 s 18.1 s -18.11%
❌ test_perf_inherited_required_fields[partial-base-first] 1.2 s 1.4 s -17.94%
❌ test_perf_openapi_large 3.1 s 3.7 s -17.57%
❌ test_perf_scalar_root_collapsed_builtin 205.1 ms 248.7 ms -17.53%
❌ test_perf_large_models_single_module_stdout 1.6 s 1.9 s -17.24%
... ... ... ... ...

ℹ️ 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 opt-consolidate-d1 (0a01f85) with fix-5273-msgspec-annotated-none (fae3a38)

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 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant