Repository navigation
Read security requirements, resolve security schemes and place API key credentials in one place each - #5784
Conversation
…y credentials in one place each
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Define shared security contracts src/datamodel_code_generator/_target_contract.py, docs/architecture.md, scripts/decision_homes.toml |
The shared contract adds helpers for API-key placement, requirement parsing, scheme catalogues, operation schemes, HTTP scheme normalization, and unresolved references. Architecture and decision-home descriptions now cover these contracts. |
Use contracts in FastAPI planning src/datamodel_code_generator/_fastapi/plan.py, src/datamodel_code_generator/_fastapi/render.py, scripts/decision_homes.toml |
The FastAPI planner uses the shared helpers for scheme resolution, security requirements, scheme classification, and unresolved references. The renderer imports Requirement from _target_contract. The decision-home allowlist entry for _requirements is removed. |
Use contracts in client security src/datamodel_code_generator/_client/security.py |
The client security planner uses shared helpers for scheme classification, catalogues, operation-specific schemes, and requirement alternatives. It retains diagnostics and validation for malformed requirements, unavailable schemes, scopes, and ownership. |
Resolve API-key authentication names src/datamodel_code_generator/_openapi_wire_plan.py |
The OpenAPI wire planner resolves schemes and requirements through shared catalogues, then returns deduplicated API-key locations and names. Parameter-collision checks use the shared API-key locations. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Refactor
Possibly related issues
datamodel-code-generator/datamodel-code-generator#5780— This issue concerns anapiKeyheader scheme in generated server code. The pull request changes API-key placement and security-scheme resolution.
Suggested labels: breaking-change-analyzed
Merge Risk: 
Minimal · up to cf63a
-
No actionable merge-blocking issue is established. The shared security-contract integration appears mergeable subject to normal checks.
Pre-merge checks: 
5
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 82.35% 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 17 functions across 5 files. (2 skipped: 2 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.
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. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will improve performance by 11.43%1 warning
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
Breaking Change AnalysisResult: No breaking changes detected Reasoning: This PR is an internal refactor. Security-scheme reading for the OpenAPI client, the FastAPI target and the wire plan moves into new shared helpers in the private module _target_contract.py: api_key_place, requirement_alternatives, security_requirements, scheme_catalogues, operation_schemes, http_scheme and unresolved_reference. The old private copies are removed: _key_scheme, _requirements, _entry, _scopes, _requirement_names and _API_KEY_LOCATIONS. The Requirement type alias moves from _fastapi/plan.py to _target_contract.py, and the only other changes are docs and the internal decision_homes.toml. All touched modules are private, so no public API or CLI option changes. For valid documents the logic is the same: apiKey location and name checks including the token check, lower-case http scheme matching, oauth2 and openIdConnect handling, unresolved reference checks, security requirement validation, per-document scheme lookup and the collision-loop order. The only differences are in edge cases with malformed security declarations, which the planners already report as errors. The behaviour diff gate does list accepted cells, but they compare against the last release, and their notes put them down to allOf schemas whose parts admit no object becoming root models or aliases. This diff does not touch JSON Schema parsing or model generation, so those output changes come from a different change. No code generation, template, API, CLI, default-behaviour, Python-version or error-handling breaking changes come from this diff. This analysis was produced by the release draft workflow |
|
🎉 Released in 0.88.0 This PR is now available in the latest release. See the release notes for details. |
Summary by CodeRabbit