Skip to content

Keep one TypedDict request-response class for models an inline allOf member closes beside a schema additionalProperties - #5298

Merged
Koudai Aono (koxudaxi) merged 1 commit into
fix-5286-typed-extra-allof-falsefrom
fix-5290-closed-typeddict-extras
Oct 24, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
fix-5286-typed-extra-allof-falsefrom
fix-5290-closed-typeddict-extras

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Fixes: #5290

Summary by CodeRabbit

  • Bug Fixes
    • Generated request and response models now correctly reflect schemas that prohibit additional fields, including within composed schemas.
    • When schemas allow extra fields with a defined value type, generated models now preserve the appropriate request- and response-specific types.

…member closes beside a schema additionalProperties

An inline allOf member with additionalProperties false closes the TypedDict, so set_additional_properties writes
closed=True and no extra_items type, but the request-response split walk still collected the models that type
names and asked the holder for variants nobody generated. Both now read the model's additionalProperties from one
helper (_model_additional_properties), which applies the closure.

Fixes: #5290
@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 df173ab and b0b7413.

Files ignored due to path filters: 1
  • tests/data/jsonschema/read_only_write_only_closed_extra_items.json is excluded by !tests/data/**/*.json and included by none
Files selected for processing: 5
  • src/datamodel_code_generator/parser/jsonschema.py
  • tests/data/expected/main/jsonschema/read_only_write_only_closed_extra_items.py
  • tests/data/expected/main/jsonschema/read_only_write_only_closed_extra_items~main_read_only_write_only_closed_extra_items[default].py
  • tests/main/jsonschema/test_main_jsonschema.py
  • tests/main/jsonschema/test_main_jsonschema.refs

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 parser now uses effective additionalProperties values when generating extra-item metadata and analyzing request/response references. Tests cover closed inline allOf models and open models with request- and response-specific extra-item types.

Changes: JSON Schema request/response models

Layer / File(s) Summary
Effective additionalProperties selection
src/datamodel_code_generator/parser/jsonschema.py
A shared helper selects False when an inline allOf source closes a model without patternProperties. The parser uses this value for extra-item metadata and request/response reference analysis.
Closed extra-items behavior and validation
tests/main/jsonschema/test_main_jsonschema.py, tests/main/jsonschema/test_main_jsonschema.refs, tests/data/expected/main/jsonschema/read_only_write_only_closed_extra_items.py, tests/data/expected/main/jsonschema/read_only_write_only_closed_extra_items~main_read_only_write_only_closed_extra_items[default].py
Parametrized tests cover deduplicated and default request/response generation, schema validation, and msgspec decoding. Expected outputs include closed types and open types with distinct request and response extra-item types.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related issues

Possibly related PRs

Merge Risk: Minimal · up to b0b74

The change appears mergeable after normal test checks. No actionable merge-blocking issue was established.

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 identifies the main change: preserving one request-response TypedDict class when an inline allOf member closes the model alongside schema-valued additionalProperties. The wording is awkward …
Linked Issues check Passed Issue #5290 requires TypedDict generation to handle an inline allOf member with additionalProperties: false when the model also has schema-valued additionalProperties. The implementation central…
Out of Scope Changes check Passed The changes stay within issue #5290. The source change fixes additional-properties handling and request/response variant analysis. The test, reference entry, and generated snapshots verify the reporte…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Title check

Explanation

The title identifies the main change: preserving one request-response TypedDict class when an inline allOf member closes the model alongside schema-valued additionalProperties. The wording is awkward but specific and related to the changeset.

Full details: Linked Issues check

Explanation

Issue #5290 requires TypedDict generation to handle an inline allOf member with additionalProperties: false when the model also has schema-valued additionalProperties. The implementation centralizes this decision in _model_additional_properties. set_additional_properties and request/response reference analysis both use the helper. The added test and snapshots cover closed models, schema-valued extra items, and request/response generation. The expected output contains closed TypedDicts without extra_items, and separate request/response extra-item types where required.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #5290. The source change fixes additional-properties handling and request/response variant analysis. The test, reference entry, and generated snapshots verify the reported TypedDict generation behavior. No unrelated production behavior or unrelated test area is shown.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 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 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-24T08:10:35.899312Z b0b7413 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 14.08%

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

❌ 23 regressed benchmarks
✅ 27 untouched benchmarks
⏩ 98 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_perf_unique_items_runtime_scalar_validation 1.5 ms 1.9 ms -20.55%
❌ test_perf_client_calls[sync] 18.2 ms 22.2 ms -18.2%
❌ test_perf_kubernetes_style_pydantic_v2 1.4 s 1.7 s -17.75%
❌ test_perf_stripe_style_pydantic_v2 1.2 s 1.5 s -17.63%
❌ test_perf_unique_items_nested_model_validation 1.6 ms 1.9 ms -17.29%
❌ test_perf_client_calls[async] 20.1 ms 24.2 ms -16.85%
❌ test_perf_pydantic_field_name_resolution 958.3 µs 1,144.9 µs -16.3%
❌ test_perf_all_options_enabled 3.5 s 4.1 s -15.3%
❌ test_perf_openapi_large 1.8 s 2.1 s -14.5%
❌ test_perf_complex_refs 1.2 s 1.4 s -14.08%
❌ test_perf_large_models_pydantic_v2 1.9 s 2.3 s -13.98%
❌ test_perf_load_pyproject_config[mapping-None] 176 µs 202.9 µs -13.29%
❌ test_perf_load_pyproject_config[config-multiple] 176.6 µs 202.3 µs -12.69%
❌ test_perf_load_pyproject_config[mapping-multiple] 176.8 µs 202.1 µs -12.53%
❌ test_perf_duplicate_names 581.3 ms 661.3 ms -12.09%
❌ test_perf_extreme_large_schema 8.5 s 9.7 s -12%
❌ test_perf_aws_style_openapi_pydantic_v2 1.2 s 1.3 s -11.71%
❌ test_perf_simple_msgspec_unset_field_rendering 75.6 ms 85.5 ms -11.51%
❌ test_perf_graphql_style_pydantic_v2 459.4 ms 517.6 ms -11.24%
❌ test_perf_large_models_pydantic_v2_noformat 757.1 ms 853 ms -11.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 fix-5290-closed-typeddict-extras (b0b7413) with fix-5286-typed-extra-allof-false (df173ab)

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!

@koxudaxi
Koudai Aono (koxudaxi) merged commit 921a0f9 into main Oct 24, 2026
131 of 132 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the fix-5290-closed-typeddict-extras branch October 24, 2026 09:10
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: Breaking changes detected

Reasoning: The PR moves the allOf-closing logic out of set_additional_properties into a new private helper, _model_additional_properties, and uses that helper in the request-response reference walk in _get_ref_schema_rw_model_reference_facts. Before, the walk read model_schema.additionalProperties directly. So a TypedDict model closed by an inline allOf member with additionalProperties false still pulled in its schema-valued additionalProperties references, and any readOnly or writeOnly fields there split the model into Request and Response variants. Now those closed models keep one class, as the new expected output shows: Closed, ClosedNested and Inner appear as single closed=True classes, while Open still splits with its extra_items type. This is a bug fix for a narrow combination of options, but it renames classes in generated output for affected schemas, so it is listed as a code generation change. The set_additional_properties refactor itself does not change behavior, because the bool branch already handled the allOf-closed case. No CLI options, public API, templates, defaults or Python version support were removed or changed.

Content for Release Notes

Code Generation Changes

  • TypedDict models closed by an inline allOf member no longer split into request and response variants - When using --output-model-type typing.TypedDict with --read-only-write-only-model-type request-response, a model whose additionalProperties references a schema with readOnly or writeOnly fields, but which an inline allOf member closes with additionalProperties: false (including nested allOf and inline object properties), now generates a single closed=True class such as Closed instead of separate ClosedRequest and ClosedResponse classes. The extra_items type is never written for these closed models, so the split classes were identical. Code that imports or references the old ...Request and ...Response class names for these models has to use the single class name instead (Keep one TypedDict request-response class for models an inline allOf member closes beside a schema additionalProperties #5298)

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.

TypedDict request-response models crash when an inline allOf closes a model whose additionalProperties reaches a readOnly model

1 participant