Skip to content

Report path, webhook, callback, method and AsyncAPI names that are not strings as schema errors - #5250

Merged
Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
fix-5222-numeric-keys
Oct 24, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
fix-5222-numeric-keys

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Fixes: #5222

Summary by CodeRabbit

  • Bug Fixes
    • OpenAPI and AsyncAPI parsing now reports clearer, location-specific errors when component names, paths, webhook or callback names, methods, or schema-format values are invalid.
    • Invalid non-string names are identified with their corresponding schema paths, making malformed API definitions easier to locate and correct.

@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 1c7e801 and f3a465c9bf1510df84fa87c79db5f8a5bf037d99.

⛔ Files ignored due to path filters: 8
  • tests/data/malformed/integer_additional_operation.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/malformed/integer_asyncapi_channel.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/malformed/integer_asyncapi_component.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/malformed/integer_asyncapi_schema_format.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/malformed/integer_callback_expression.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/malformed/integer_callback_name.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/malformed/integer_path.yaml is excluded by !tests/data/**/*.yaml and included by none
  • tests/data/malformed/integer_webhook.yaml is excluded by !tests/data/**/*.yaml and included by none
📒 Files selected for processing: 4
  • src/datamodel_code_generator/parser/asyncapi.py
  • 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; 2 remain after this review.

📝 Walkthrough

The parsers now validate non-string OpenAPI and AsyncAPI mapping keys before using them in names or paths. Invalid keys produce located schema errors. Regression tests cover paths, webhooks, callbacks, operation methods, AsyncAPI component and channel names, and schemaFormat.

Changes: Schema key validation

Layer / File(s) Summary
OpenAPI component and item names
src/datamodel_code_generator/parser/openapi.py, tests/main/test_error_messages.py
OpenAPI component and request-body component names use shared key validation. Path and webhook item names are checked before processing. Tests assert located errors for non-string path and webhook names.
OpenAPI operation and callback keys
src/datamodel_code_generator/parser/openapi_scope.py, tests/main/test_error_messages.py
Path-scope traversal validates operation-name keys and callback names and expressions. Tests assert errors for numeric callback names, callback expressions, and additional-operation methods.
AsyncAPI schema path keys
src/datamodel_code_generator/parser/asyncapi.py, tests/main/test_error_messages.py
AsyncAPI path formatting stringifies path components, and schema-format processing rejects non-string path components. Tests cover numeric component and channel names and non-string schemaFormat.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

Merge Risk: ⚪ Minimal · up to f3a46

No actionable merge-blocking issue is established. The changes improve malformed-schema diagnostics and include targeted regression tests; normal checks should pass before merging.

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: reporting non-string OpenAPI and AsyncAPI names as schema errors.
Linked Issues check Passed The PR addresses the coding requirements in #5222. openapi.py validates non-string component, path, and webhook keys and raises located SchemaParseError values. openapi_scope.py validates operat…
Out of Scope Changes check Passed The changes remain within the linked issue's error-handling scope. Callback names and expressions, additional-operation methods, AsyncAPI channel names, and schemaFormat use the same non-string-key …
Docstring Coverage Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 4 files.
Full details: Linked Issues check

Explanation

The PR addresses the coding requirements in #5222. openapi.py validates non-string component, path, and webhook keys and raises located SchemaParseError values. openapi_scope.py validates operation, callback, webhook, and method keys before path construction. asyncapi.py stringifies schema locations and rejects paths with non-string components through the parser key error. test_error_messages.py adds regression cases for the required OpenAPI path and webhook inputs and AsyncAPI component names. The specified YAML fixtures are excluded from review, but the reviewed source and test summary establish the intended diagnostics.

Full details: Out of Scope Changes check

Explanation

The changes remain within the linked issue's error-handling scope. Callback names and expressions, additional-operation methods, AsyncAPI channel names, and schemaFormat use the same non-string-key validation needed to prevent name or path construction failures. The added tests verify these related diagnostics. No unrelated feature or behavioral change is identified in the reviewed whole-PR summary.

✨ 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-23T18:06:46.671924Z f3a465c 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

@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: f3a465c9bf

ℹ️ 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 20.14%

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

❌ 43 regressed benchmarks
✅ 7 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] 425.7 ms 593.2 ms -28.22%
❌ test_perf_unique_items_runtime_scalar_validation 1.5 ms 2 ms -27.37%
❌ test_perf_ordinary_array_constraint_generation 1.3 s 1.8 s -26.34%
❌ test_perf_false_reference_validation 172 ms 233.4 ms -26.32%
❌ test_perf_client_calls[sync] 17.8 ms 23.8 ms -25.18%
❌ test_perf_inherited_required_fields[partial-derived-first] 624.4 ms 828.9 ms -24.67%
❌ test_perf_simple_pydantic_v2_field_construction 5.9 ms 7.8 ms -24.51%
❌ test_perf_unique_items_nested_model_validation 1.6 ms 2.1 ms -24.48%
❌ test_perf_local_reference_file_resolution 84.8 ms 110.8 ms -23.51%
❌ test_perf_scalar_root_collapsed_builtin 115.4 ms 150.2 ms -23.18%
❌ test_perf_duplicate_names 587.9 ms 764.5 ms -23.09%
❌ test_perf_large_models_typed_dict[legacy-requiredness] 699.5 ms 904.5 ms -22.67%
❌ test_perf_large_models_typed_dict[total-false-requiredness] 692 ms 893.4 ms -22.55%
❌ test_perf_inherited_required_fields[partial-base-first] 687.4 ms 887.1 ms -22.51%
❌ test_perf_large_models_pydantic_v2_builtin_double_quotes 849.1 ms 1,084.8 ms -21.73%
❌ test_perf_client_calls[async] 20.4 ms 25.9 ms -21.41%
❌ test_perf_large_models_single_module_stdout 932 ms 1,184.7 ms -21.33%
❌ test_perf_complex_refs 1.2 s 1.5 s -21.22%
❌ test_perf_large_models_pydantic_v2_noformat 819.8 ms 1,038.6 ms -21.07%
❌ test_perf_pydantic_field_name_resolution 954.4 µs 1,206.7 µs -20.91%
... ... ... ... ...

ℹ️ 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-5222-numeric-keys (6e34f6f) with main (b1cbd9f)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 main (695e138) during the generation of this report, so b1cbd9f was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@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!

…t strings as schema errors

A YAML key such as `1` loads as a number. Such a key crashed with a TypeError or AttributeError as a path (the
`paths` and `api` scopes), as a webhook name (the `webhooks` scope, and the `api` scope when a model is named from
it), as a callback name or callback expression and as an `additionalOperations` method (the `api` scope), and in
AsyncAPI as any name on the way to a schema (component, channel, operation, message, parameter or binding names)
or in an AsyncAPI message that names the location below such a key. These runs now stop with "Error at schema path
'<doc>#/paths/1': path 1 is not a string" (webhook name, callback name, callback expression or method; in AsyncAPI
"name" at the schema the key leads to), like a numeric component name, or with the AsyncAPI message. Runs that never
build a name or path from such a key, such as an `api` scope webhook without operations or named by
--use-operation-id-as-name, keep their output.

Fixes: #5222
@koxudaxi
Koudai Aono (koxudaxi) merged commit 852e33f into main Oct 24, 2026
131 of 132 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the fix-5222-numeric-keys branch October 24, 2026 01:42
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR makes the OpenAPI and AsyncAPI parsers raise clear SchemaParseError messages when a YAML key that should be a string loads as some other value, such as an integer key 1. This covers path keys, webhook names, callback names, callback expressions, additionalOperations method keys, AsyncAPI channel names and AsyncAPI component schema names. It also fixes AsyncAPI path-to-string conversion so that error messages can be built when a path part is not a string. These inputs break the specs, which require string keys. Before this PR they most likely crashed with an unhandled exception, for example calling startswith on an int or redacting or joining a path that holds an int. The new check for webhook-name and method keys is skipped when use_operation_id_as_name is set, so cases where an integer key does not affect model naming keep working. The private helper _component_name was renamed to _key_name and split out into _key_error; these are internal methods, not public API. No CLI options, defaults, templates, generated output for valid inputs, or Python version support changed. Most of the diff is new malformed test fixtures and error-message tests. Overall this improves error handling for bad input and does not break existing users.


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.

Numeric YAML keys for paths, webhooks and AsyncAPI components crash with TypeError

1 participant