Skip to content

Type mapped component users in dict keys and TypedDict extra_items by their import and say DispatchTable.choose returns a Choice - #5206

Merged
Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
review-fixes-2
Oct 23, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
review-fixes-2

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved generated models for schemas that reference other types in dictionary keys and additional properties. These references are now handled more consistently across supported output formats, including cases where additional properties combine multiple types.
  • Documentation
    • Clarified how selected rows and generic base classes are described.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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 8cf9173 and 42c3e6c292bae8e4c9fab001a21794b3f0e461c8.

⛔ Files ignored due to path filters: 2
  • docs/llms-full.txt is excluded by none and included by none
  • tests/data/openapi/ref_siblings_recursive_target/mapped.yaml is excluded by !tests/data/**/*.yaml and included by none
📒 Files selected for processing: 9
  • docs/architecture.md
  • src/datamodel_code_generator/model/output.py
  • src/datamodel_code_generator/model/typed_dict.py
  • src/datamodel_code_generator/parser/_passes/cross_module.py
  • src/datamodel_code_generator/parser/jsonschema.py
  • tests/data/expected/main/openapi/main_openapi/reference_to_component_without_model_mapped[msgspec.Struct].py
  • tests/data/expected/main/openapi/main_openapi/reference_to_component_without_model_mapped[pydantic_v2.BaseModel].py
  • tests/data/expected/main/openapi/main_openapi/reference_to_component_without_model_mapped[typing.TypedDict].py
  • tests/main/openapi/test_main_openapi.py

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

📝 Walkthrough

JSON Schema definition remapping now updates dictionary-key uses and typed additional-properties references. The generated outputs reflect these changes across Pydantic, TypedDict, and msgspec. The PR also updates descriptions of DispatchTable.choose and apply_generic_base_class.

Changes: Definition reference remapping

Layer / File(s) Summary
Reference updates
src/datamodel_code_generator/model/output.py, src/datamodel_code_generator/parser/jsonschema.py, src/datamodel_code_generator/model/typed_dict.py, src/datamodel_code_generator/parser/_passes/cross_module.py
Definition references now update dictionary-key types and typed additional-properties metadata. TypedDict rendering uses the source type hint directly when no additional-property reference classes exist. The apply_generic_base_class description was also updated.
Generated output updates
tests/data/expected/main/openapi/main_openapi/reference_to_component_without_model_mapped*, tests/main/openapi/test_main_openapi.py
Expected outputs add dictionary-key aliases and models with typed additional properties for Pydantic, TypedDict, and msgspec. The test description now includes dictionary keys and TypedDict extra_items as reference locations.

Priority: ➖ Normal

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

Change: Bug fix

Possibly related issues

Possibly related PRs

Merge Risk: ⚪ Minimal · up to 42c3e

No actionable merge-blocking issue is established; the change is mergeable after 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 names two changes: mapped component users in dict keys and TypedDict extra_items now use their imports, and DispatchTable.choose is documented as returning a Choice. The main code change is …
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. Analyzed 6 functions across 6 files. (3 skipped: 1 …
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 names two changes: mapped component users in dict keys and TypedDict extra_items now use their imports, and DispatchTable.choose is documented as returning a Choice. The main code change is the import-based typing of mapped component users in dict keys and TypedDict extra_items, which the title states. The DispatchTable.choose docs fix is a minor docs-only change that the title also mentions. The title is long at 19 words, but it is 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. Analyzed 6 functions across 6 files. (3 skipped: 1 unsupported, 2 too large.)

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

❤️ Share

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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-23T12:16:31.111719Z 42c3e6c 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 23, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 16.57%

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

❌ 38 regressed benchmarks
✅ 12 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.1 s 22.4 s -28.07%
❌ test_perf_load_pyproject_config[mapping-multiple] 303.2 µs 381.9 µs -20.62%
❌ test_perf_load_pyproject_config[config-None] 290.1 µs 365.3 µs -20.6%
❌ test_perf_load_pyproject_config[mapping-None] 293.4 µs 369.1 µs -20.52%
❌ test_perf_client_calls[sync] 33.6 ms 42.1 ms -20.34%
❌ test_perf_load_pyproject_config[config-multiple] 304 µs 381.5 µs -20.32%
❌ test_perf_all_options_enabled 5.9 s 7.4 s -19.52%
❌ test_perf_client_calls[async] 36.9 ms 45.6 ms -19.08%
❌ test_perf_target_render[fastapi-large] 5.1 s 6.3 s -19.04%
❌ test_perf_extreme_large_schema 14.7 s 18.1 s -19.03%
❌ test_perf_deep_nested 5.2 s 6.4 s -18.92%
❌ test_perf_kubernetes_style_pydantic_v2 2.5 s 3.1 s -18.84%
❌ test_perf_target_render[client-large] 6.4 s 7.8 s -17.76%
❌ test_perf_complex_refs 2 s 2.5 s -17.63%
❌ test_perf_stripe_style_pydantic_v2 2 s 2.4 s -17.36%
❌ test_perf_large_models_pydantic_v2 3.5 s 4.2 s -17.14%
❌ test_perf_aws_style_openapi_pydantic_v2 2 s 2.4 s -16.97%
❌ test_perf_multiple_files_input 3.6 s 4.3 s -16.81%
❌ test_perf_graphql_style_pydantic_v2 801.1 ms 960.6 ms -16.6%
❌ test_perf_openapi_large 3 s 3.6 s -16.05%
... ... ... ... ...

ℹ️ 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 review-fixes-2 (494db72) with main (463f126)

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

Base automatically changed from ph3b-pass-modules to main October 23, 2026 12:28
… their import and say DispatchTable.choose returns a Choice
@codecov

codecov Bot commented Oct 23, 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 e3ea671 into main Oct 23, 2026
131 of 132 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the review-fixes-2 branch October 23, 2026 16:07
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR is a narrow bug fix for components that are a $ref with sibling keywords to a schema in a document mapped by --external-ref-mapping. Before, a reference to such a component was only typed by the mapped import when it appeared in a field or nested type. Now it is also typed by the import when it is a dict key from propertyNames and when it is inside typed additionalProperties, such as pydantic pydantic_extra or TypedDict extra_items. The only internal changes are a new static helper additional_properties_type_source on the output model context, a reworked _type_users_by_import, a new _type_additional_properties_by_import, and TypedDict extra_items being left unquoted when it no longer names generated classes. No CLI options, public API, defaults, templates or Python version support were removed or changed. The expected-output changes only add new test cases (Keyed, Extra, Mixed) for the newly handled positions, and the TypedDict import moving to typing_extensions comes from the new extra_items case. No existing expected output for previously supported inputs changed, so existing users are not affected.


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