Skip to content

Report component names that are not strings as schema errors - #5230

Merged
Koudai Aono (koxudaxi) merged 1 commit into
fix-4910-ryaml-retryfrom
fix-4491-component-names
Oct 23, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
fix-4910-ryaml-retryfrom
fix-4491-component-names

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Fixes: #4491

Summary by CodeRabbit

  • Bug Fixes
    • OpenAPI documents with non-string component names are now rejected with clearer errors that identify the document location and invalid name. This validation applies to schemas, request bodies, parameters, responses, headers, path items, and callbacks, helping pinpoint malformed component entries.

@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 929ada23bb9d0daafb19ce11965466f6ade65ccf and 29b47481f1d8c1a563057203a7ae0f56de6370a7.

⛔ Files ignored due to path filters: 5
  • tests/data/malformed/integer_component_callback.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/malformed/integer_component_parameter.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/malformed/integer_component_path_item.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/malformed/integer_component_request_body.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/malformed/integer_component_schema.yaml is excluded by !tests/data/**/*.yaml and included by none
📒 Files selected for processing: 3
  • src/datamodel_code_generator/parser/openapi.py
  • src/datamodel_code_generator/parser/openapi_scope.py
  • tests/main/test_error_messages.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

OpenAPI parsing now validates component names as strings. Non-string names in schemas and other component categories produce location-aware errors. Tests cover malformed names across several component categories and scopes.

Changes: OpenAPI component-name validation

Layer / File(s) Summary
Validate schema and request-body names
src/datamodel_code_generator/parser/openapi.py
Added validation for component names. Schema and request-body parsing now uses validated string names.
Validate names during component traversal
src/datamodel_code_generator/parser/openapi_scope.py, tests/main/test_error_messages.py
Component traversal validates names for parameters, responses, headers, path items, callbacks, and discriminator schemas. Tests check location-aware errors for non-string names.

Priority: ➖ Normal

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

Change: Bug fix

Possibly related PRs

Merge Risk: ⚪ Minimal · up to 29b47

The component-name validation is ready to merge after normal checks; no actionable compatibility issue remains.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive The changes address the integer component-name crash. openapi.py validates non-string schema and request-body names, and openapi_scope.py uses named-component iteration for the affected component … Provide reviewable code or test evidence at the reviewed head that an OpenAPI schema containing allOf: [true] or another boolean member produces a diagnostic instead of an uncaught exception.
Passed Passed checks: 4 passed
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: reporting non-string OpenAPI component names as schema errors.
Out of Scope Changes check Passed The changes stay within the linked issue scope. Validation of non-string component names prevents the reported OpenAPI parsing crashes. The broader handling for parameters, request bodies, responses, …
Docstring Coverage Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files.
Full details: Out of Scope Changes check

Explanation

The changes stay within the linked issue scope. Validation of non-string component names prevents the reported OpenAPI parsing crashes. The broader handling for parameters, request bodies, responses, headers, path items, callbacks, schemas, and discriminators supports the same component-name failure mode. The added tests verify these related scope paths. No unrelated change is identified.

Full details: Linked Issues check

Explanation

The changes address the integer component-name crash. openapi.py validates non-string schema and request-body names, and openapi_scope.py uses named-component iteration for the affected component mappings. The added tests cover integer names under schemas, api, requestbodies, and other API component scopes. The available evidence does not establish that boolean schemas inside allOf produce diagnostics at the reviewed head. The reference to #5159 is not code evidence.

Resolution

Provide reviewable code or test evidence at the reviewed head that an OpenAPI schema containing allOf: [true] or another boolean member produces a diagnostic instead of an uncaught exception.

✨ 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-23T15:48:40.572194Z 29b4748 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 29b47481f1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

@codspeed

codspeed Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 10.49%

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

❌ 1 regressed benchmark
✅ 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_inherited_required_fields[required-base-first] 853.4 ms 953.4 ms -10.49%

Tip

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


Comparing fix-4491-component-names (a699f8e) with fix-4910-ryaml-retry (6400968)

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

@github-actions

Copy link
Copy Markdown
Contributor

A YAML key such as `1` under `components` loads as a number. The legacy
scopes crashed on such a name under `schemas` and `requestBodies`, and the
`api` scope on every component kind it reads (and on any loaded document's
`schemas`). They now stop with "Error at schema path '<doc>#/components/<kind>/1':
component name 1 is not a string". Runs that never use such a name as a model
name, such as a legacy request body without a schema, keep their output.

Boolean schemas in `allOf` no longer crash since #5159.

Fixes: #4491
@koxudaxi
Koudai Aono (koxudaxi) merged commit e28be1d into main Oct 23, 2026
25 of 26 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the fix-4491-component-names branch October 23, 2026 19:11
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR adds two internal helpers to the OpenAPI parser, _component_name and _named_components. They check that every key under components schemas, requestBodies, parameters, responses, headers, pathItems and callbacks is a string. A key like an unquoted YAML 1, which loads as a number, now raises a SchemaParseError that names the component location and says the component name is not a string. The changed call sites only wrap the existing loops, and they pass on the same string keys as before, so valid specifications produce the same generated code. No CLI options, public API, templates, defaults or supported Python versions change; the helpers are private and the deleted lines only show those loops being rewritten. The new test fixtures sit in the malformed test directory and are checked in the error-message tests, so this looks like clearer error reporting for invalid input, which most likely failed during processing before. I could not confirm the old behaviour from the diff alone. Overall I don't see this as a breaking change.


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.

OpenAPI parsing crashes on integer component keys and on boolean schemas in allOf

1 participant