Skip to content

Resolve OpenAPI and AsyncAPI document references on the graph - #5167

Merged
Koudai Aono (koxudaxi) merged 1 commit into
rp15a-import-plansfrom
fe8-document-refs
Oct 23, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
rp15a-import-plansfrom
fe8-document-refs

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of converted schemas so they are mounted in the schema graph without modifying the loaded document.
    • Corrected discriminator schema references so schemas and allOf subtypes are registered under references based on their own document locations.

@coderabbitai

coderabbitai Bot commented Oct 22, 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 3b2fce7af3c71770501e4325f9d60346daade010 and 6a3bc3373e94121f5de65e848a9e1a28e8db8497.

⛔ 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/parser/_schema_graph.py
  • src/datamodel_code_generator/parser/asyncapi.py
  • src/datamodel_code_generator/parser/openapi.py
  • src/datamodel_code_generator/parser/openapi_scope.py

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 schema graph now mounts converted schemas under graph-owned document roots. OpenAPI discriminator schema and subtype references use keys derived from their own schema locations. Architecture documentation describes the mounting and discriminator registration behavior.

Changes: Schema graph updates

Layer / File(s) Summary
Schema graph mounting
src/datamodel_code_generator/parser/_schema_graph.py
SchemaGraphBuilder tracks mount roots and containers, copies document roots and containers for mounting, and adds RefOrigin.DISCRIMINATOR_SCHEMA.
OpenAPI discriminator reference keys
src/datamodel_code_generator/parser/openapi.py, src/datamodel_code_generator/parser/openapi_scope.py, docs/architecture.md
Discriminator schemas and allOf subtypes use reference keys derived from each schema’s location. The graph preserves resolved-reference edges. The documentation describes discriminator registration under each schema’s own-document key.
AsyncAPI converted-schema mounting
src/datamodel_code_generator/parser/asyncapi.py, docs/architecture.md
AsyncAPI indexes documents through mount_root and inserts converted payload schemas through mount_in. The documentation states that mounting does not write to the loaded document.

Priority: ➖ Normal

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 6a3bc

The reference and mounting changes have no identified merge-blocking defect; the reported crash requires reusing a parser after disposal.

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 clearly and concisely describes the main change: resolving OpenAPI and AsyncAPI document references through the schema graph.
Docstring Coverage Passed Docstring coverage is 92.86% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 4 files. (1 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: Docstring Coverage

Explanation

Docstring coverage is 92.86% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 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

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-22T23:35:48.919632Z 6a3bc33 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.

@codspeed

codspeed Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 30.59%

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 regressed benchmarks
✅ 2 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.6 ms 2.6 ms -41.09%
❌ test_perf_unique_items_nested_model_validation 1.7 ms 2.7 ms -39.64%
❌ test_perf_client_calls[sync] 18.6 ms 30.3 ms -38.56%
❌ test_perf_client_calls[async] 20.7 ms 33.7 ms -38.43%
❌ test_perf_large_models_pydantic_v2 1.9 s 3 s -36.26%
❌ test_perf_duplicate_names 565.7 ms 886.3 ms -36.18%
❌ test_perf_pydantic_field_name_resolution 1 ms 1.6 ms -35.69%
❌ test_perf_large_models_typed_dict[total-false-requiredness] 657 ms 1,018.7 ms -35.51%
❌ test_perf_large_models_pydantic_v2_builtin 702.3 ms 1,088.7 ms -35.49%
❌ test_perf_large_models_pydantic_v2_noformat 700.3 ms 1,085.5 ms -35.48%
❌ test_perf_large_models_pydantic_v2_builtin_double_quotes 735 ms 1,124.5 ms -34.64%
❌ test_perf_large_models_single_module_stdout 798.4 ms 1,213.3 ms -34.19%
❌ test_perf_complex_refs 1.2 s 1.8 s -33.82%
❌ test_perf_large_models_typed_dict[legacy-requiredness] 653 ms 986.2 ms -33.79%
❌ test_perf_unique_items_runtime_nested_object_validation 4.3 ms 6.3 ms -32.83%
❌ test_perf_extreme_large_schema 8.6 s 12.8 s -32.35%
❌ test_perf_load_yaml_openapi_large 20.5 ms 30 ms -31.76%
❌ test_perf_simple_pydantic_v2_field_construction 6.1 ms 8.9 ms -31.52%
❌ test_perf_deep_nested 3.1 s 4.5 s -31.15%
❌ test_perf_multiple_files_input 2.3 s 3.4 s -31.11%
... ... ... ... ...

ℹ️ 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 fe8-document-refs (b451e60) with rp15a-import-plans (3b2fce7)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 rp15a-import-plans (37f87b5) during the generation of this report, so 6c4b947 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@github-actions

Copy link
Copy Markdown
Contributor

@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 dc85321 into main Oct 23, 2026
24 of 25 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the fe8-document-refs branch October 23, 2026 04:16
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR only changes internal parser code and documentation. It adds a DISCRIMINATOR_SCHEMA value to the internal RefOrigin enum. It adds mount_root and mount_in methods to the internal SchemaGraphBuilder, so converted AsyncAPI payloads from Protocol Buffers or XML Schema are mounted under a copy of the root owned by the graph instead of being written into the loaded document. It also adds a private _schema_key helper, so OpenAPI, scoped OpenAPI and AsyncAPI register discriminator schemas and subtypes under the key resolved from the schema's own document rather than the current resolver context. These are refactorings of private internals and bug fixes for multi-document discriminator resolution. No CLI options, public Python API, template variables, defaults, supported Python versions or error reporting change, and nothing public is removed in the diff, so there are no breaking changes.


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.

2 participants