Skip to content

Write the array an itemSchema stands for, parse the schema of a media type, read the reference a discriminator mapping value names and build the schema of a reference beside its siblings in one place each - #5966

Merged
Koudai Aono (koxudaxi) merged 4 commits into
next13-3from
next13-4
Nov 2, 2026
Merged

Koudai Aono (koxudaxi) merged 4 commits into
next13-3from
next13-4

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of discriminator mappings so schema names and references resolve correctly.
    • Improved schema generation for referenced schemas with array constraints, including contains bounds and unsatisfiable enum or const results.
  • New Features
    • Added support for representing OpenAPI 3.2 itemSchema arrays.
    • Improved request and response media-schema parsing, including skipping media entries without schemas.

@coderabbitai

coderabbitai Bot commented Nov 2, 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 3499f1a and 87b07f5.

Files ignored due to path filters: 1
  • docs/llms-full.txt is excluded by none and included by none
Files selected for processing: 5
  • docs/architecture.md
  • src/datamodel_code_generator/_document_reader.py
  • src/datamodel_code_generator/_fastapi/source_document.py
  • src/datamodel_code_generator/parser/_schema_refs.py
  • src/datamodel_code_generator/parser/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

The changes update reference-sibling merging, discriminator mapping normalization, and OpenAPI 3.2 parsing for itemSchema and media schemas.

Changes: Reference and OpenAPI parsing

Layer / File(s) Summary
Reference-sibling intersection
src/datamodel_code_generator/parser/_schema_refs.py, docs/architecture.md
intersect_ref_siblings_schema combines holder array constraints with contains-derived item bounds and retains a supplied target reference. merge_ref_with_schema delegates intersection and metadata handling to it.
Discriminator mapping normalization
src/datamodel_code_generator/_document_reader.py, src/datamodel_code_generator/_fastapi/source_document.py, src/datamodel_code_generator/parser/openapi.py
discriminator_mapping_ref leaves values containing / or # unchanged and prefixes other values with #/components/schemas/. The FastAPI and OpenAPI readers use the helper to normalize mapping values.
OpenAPI media schema parsing
src/datamodel_code_generator/parser/openapi.py, docs/architecture.md
A shared helper constructs the array representation for itemSchema. _parse_media_schema is used for request-body and response media schemas, which are added only when parsing returns a data type. The architecture decision table documents these paths and discriminator mapping interpretation.

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

Change: Refactor

Merge Risk: Minimal · up to 87b07

No merge-blocking issue is identified in these parsing consolidations. The change is 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 identifies all four main changes: OpenAPI itemSchema arrays, media-type schema parsing, discriminator mapping references, and reference-sibling handling. It is longer than preferr…
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 identifies all four main changes: OpenAPI itemSchema arrays, media-type schema parsing, discriminator mapping references, and reference-sibling handling. It is longer than preferred but remains specific and clearly 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 11 functions across 4 files. (1 skipped: 1 unsupported.)

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

Warning

Some tools did not complete. Review the errors below.

LanguageTool
docs/architecture.md

LanguageTool checks are incomplete because the per-file request limit of 5 was reached. Remaining text was skipped; findings from completed checks are retained.

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

@koxudaxi
Koudai Aono (koxudaxi) marked this pull request as ready for review November 2, 2026 11:46
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 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-11-02T11:47:35.879735Z 87b07f5 Draft marked ready
ℹ️ 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

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Nov 2, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 16.27%

1 warning

⚠️ 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

❌ 3 regressed benchmarks
✅ 49 untouched benchmarks
⏩ 98 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_perf_simple_pydantic_v2_field_construction 10.8 ms 13.8 ms -22.19%
❌ test_perf_load_yaml_openapi_large 34.8 ms 40.9 ms -14.93%
❌ test_perf_large_models_pydantic_v2_builtin_double_quotes 1.4 s 1.6 s -11.31%

Tip

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


Comparing next13-4 (87b07f5) with next13-3 (3499f1a)

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 Nov 2, 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 b538521 into main Nov 2, 2026
163 of 164 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the next13-4 branch November 2, 2026 13:24
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The diff is an internal refactor with no user-visible effect. The private OpenAPIParser method _normalize_discriminator_mapping_ref was replaced by a shared helper discriminator_mapping_ref in _document_reader.py with identical logic, and the FastAPI source document now calls the same helper through a new discriminator_target method that keeps the previous branches. The contains-bounds and target-ref handling moved from merge_ref_with_schema into intersect_ref_siblings_schema behind new optional holder and target_ref parameters that default to None, and the steps run in the same order, so existing callers behave the same. In openapi.py the itemSchema array construction and the per-media-type parsing in parse_request_body and parse_responses were extracted into _item_schema_array and _parse_media_schema without changing the paths, locations or skip-on-missing-schema behavior. The docs changes only add or update rows of the architecture decision table. The behaviour diff accepted cells describe allOf parts that admit no object becoming root models or aliases. This diff does not touch that logic, so those cells come from other changes since the last release. The remaining cells are both-fail or crash-fix. No public CLI option, Python API, template, default value, Python version support or error handling was changed.


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