Skip to content

Call the schema resource and definition cores directly - #6702

Merged
Koudai Aono (koxudaxi) merged 1 commit into
bspeed-reversefrom
dry-01
Nov 11, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
bspeed-reversefrom
dry-01

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Refactor
    • Updated internal schema document and reference handling across JSON Schema, OpenAPI, and AsyncAPI parsing. The changes reorganize how schema-related operations are shared across these formats. No new end-user features or visible behavior changes are described in this update.

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change separates document naming and schema-resource operations into host protocols and module-level helpers. Schema-reference and schema-processing code now calls those helpers directly. JSON Schema, AsyncAPI, and OpenAPI code also uses the shared document lookup helper.

Changes: Schema resource helper migration

Layer / File(s) Summary
Define schema-resource host contracts and helpers
src/datamodel_code_generator/parser/_schema_documents.py
Adds protocols for document naming and schema-resource access. Narrows helper host types and updates schema-document operations to call module-level helpers.
Migrate schema-processing consumers
src/datamodel_code_generator/parser/_schema_refs.py, src/datamodel_code_generator/parser/_inherited_schemas.py, src/datamodel_code_generator/parser/_rw_split.py
These modules use schema-document helpers in place of parser methods. Their host protocols inherit the relevant schema-resource protocol, and obsolete method declarations are removed.
Update parser integrations
src/datamodel_code_generator/parser/jsonschema.py, src/datamodel_code_generator/parser/asyncapi.py, src/datamodel_code_generator/parser/openapi.py
JSON Schema removes parser wrappers and calls the shared helpers. AsyncAPI and OpenAPI use the shared document lookup when recording document dialect or identity.

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

Change: Refactor

Possibly related PRs

Merge Risk: Minimal · up to 41006

No concrete regression from the helper migration is established; the PR 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 summarizes the main change: parser code now calls schema-resource and definition helpers directly.
Docstring Coverage Passed Docstring coverage is 93.48% 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. Documentati…
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 93.48% 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 46 functions across 7 files.

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between cfe314f and 41006f6.

Files selected for processing: 7

  • src/datamodel_code_generator/parser/_inherited_schemas.py
  • src/datamodel_code_generator/parser/_rw_split.py
  • src/datamodel_code_generator/parser/_schema_documents.py
  • src/datamodel_code_generator/parser/_schema_refs.py
  • src/datamodel_code_generator/parser/asyncapi.py
  • src/datamodel_code_generator/parser/jsonschema.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.

@koxudaxi
Koudai Aono (koxudaxi) marked this pull request as ready for review November 10, 2026 23:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T23:43:06.934176Z 41006f6 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

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Nov 10, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 4.98%

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

⚡ 5 improved benchmarks
❌ 7 regressed benchmarks
✅ 41 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 5.9 ms 8.9 ms -34.42%
❌ test_perf_load_yaml_openapi_large 19 ms 23.6 ms -19.36%
❌ test_perf_large_models_typed_dict[total-false-requiredness] 646.4 ms 733.6 ms -11.89%
❌ test_perf_large_models_dataclass_builtin 773.2 ms 873.5 ms -11.48%
❌ test_perf_large_models_typed_dict[legacy-requiredness] 674.1 ms 753.9 ms -10.58%
❌ test_perf_empty_pydantic_v2_field_render_plans 19.5 ms 21.7 ms -10.52%
❌ test_perf_target_render[client-small] 20.6 ms 22.9 ms -10.03%
⚡ test_perf_inherited_required_fields[required-derived-first] 573.4 ms 495.8 ms +15.66%
⚡ test_perf_inherited_required_fields[partial-base-first] 905.4 ms 796 ms +13.74%
⚡ test_perf_unique_items_schema_validators 1.3 s 1.1 s +12.19%
⚡ test_perf_inherited_required_fields[required-base-first] 506.2 ms 455.4 ms +11.17%
⚡ test_perf_scalar_root_collapsed_builtin 136.8 ms 123.1 ms +11.13%

Tip

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


Comparing dry-01 (41006f6) with bspeed-reverse (cfe314f)

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

@koxudaxi
Koudai Aono (koxudaxi) merged commit bdb6420 into main Nov 11, 2026
54 of 144 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR is an internal refactor of the parser modules. The parser host Protocol classes were split so shared members live in new DocumentNamesHost and SchemaResourcesHost protocols, and the private underscore-prefixed JsonSchemaParser wrapper methods were removed: _lenient_ref, _plain_name_ref, _note_plain_name, _schema_resource_document, _iter_schema_resource_children, _resolve_schema_resource_ref, _iter_schema_definition_entries and _reads_dynamic_anchors_in_document_order. Each wrapper only forwarded to a module-level function in _schema_documents or read config.read_dynamic_anchors_in_document_order, and callers now call those directly, so the logic is the same. Only private names in private modules were removed, so no public Python API, CLI option, template or error path changes. Every behaviour diff cell is both-fail, with no accepted or violation cells, so default generated output does not change.


This analysis was produced by the release draft workflow

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Released in 0.93.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