Repository navigation
Report a response status given by both an integer and a string key as a server and client schema error - #5284
Conversation
… a server and client schema error YAML loads a status key such as `200` as a number, so one responses object can give the same status twice, as `200` and as `'200'`. Server and client generation locate every response by the text of its status, so such a document crashed with the internal BindingCaptureError "Source pointer is ambiguous between string and integer keys". These runs now stop with "Error at schema path '<doc>#/paths/~1pets/get/responses/200': response status 200 is given by two keys, 200 and '200'", like the key errors of #5248 and #5260, and write nothing. Model generation, and server and client output of documents that give each status once, stay the same. Fixes: #5271
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Normalize and validate response statuses src/datamodel_code_generator/_target_binding.py, tests/api_generation/test_generate_targets.py, tests/api_generation/test_generate_targets.refs |
Response status keys are normalized before bindings are created. Colliding keys now raise SchemaParseError at the status pointer. Tests add client and server cases for integer and string keys representing the same status. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Low
Possibly related PRs
- datamodel-code-generator/datamodel-code-generator#5281: Both changes update target-binding key validation and the shared client/server key-error tests.
Merge Risk: 
Minimal · up to dcc13
-
No actionable issue is identified in the duplicate response-status handling; the PR is mergeable after normal checks.
Pre-merge checks: 
5
-
Full details: Linked Issues check
-
Explanation
The changes satisfy the coding requirement in
#5271._Contracts.statusesnormalizes response keys and rejects an integer/string collision, such as200and'200', withSchemaParseErrorat the response-status schema path.operationuses the normalized mapping and no longer raisesBindingCaptureError. Regression coverage adds the malformed fixture and expected client and server error cases.
Full details: Out of Scope Changes check
-
Explanation
The reviewed changes are limited to response-status validation in
_target_binding.pyand regression tests for the duplicate-status failure. These changes directly support#5271. No unrelated product behavior or unrelated files are identified in the supplied summary.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 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.
Comment @coderabbitai help to get the list of available commands.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
Merging this PR will improve performance by 96.79%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Breaking Change AnalysisResult: No breaking changes detected Reasoning: The PR changes how target binding handles an OpenAPI YAML document where a response status appears twice, once as an integer key like 200 and once as the string key '200'. Before, this raised the internal BindingCaptureError from the private _generation_contract module with a generic message. The test fixture notes called that a bug, since the internal exception escaped instead of becoming a diagnostic. Now a new static helper, statuses, finds the duplicate and raises the public SchemaParseError, a subclass of Error, with the schema path and a clear message. Input that was rejected before is still rejected and nothing is written. Only the exception moves from an internal class to the documented public error type, so this is a bug fix in error reporting, not a breaking change. Valid schemas are unaffected: response statuses are still turned into strings and processed in the same order. There are no changes to generated code output, templates, CLI options, public API signatures, defaults, or supported Python versions. The other changed files are tests and fixtures. This analysis was produced by the release draft workflow |
Fixes: #5271
Summary by CodeRabbit