Skip to content

Read security requirements, resolve security schemes and place API key credentials in one place each - #5784

Merged
Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
impl-c20-4
Oct 31, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
impl-c20-4

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved security configuration handling for API-key credentials in query parameters, headers, or cookies, and for HTTP basic and bearer schemes.
    • Improved resolution of security schemes declared across documents and handling of operation-specific requirements.
    • Improved reporting of malformed requirements, unavailable schemes, invalid scopes, overlapping ownership, and unresolved references.
  • Documentation
    • Updated architecture guidance on API-key placement, security planning, and references to missing objects or unloaded documents.

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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 400d6c5 and cf63a0d.

Files ignored due to path filters: 1
  • docs/llms-full.txt is excluded by none and included by none
Files selected for processing: 7
  • docs/architecture.md
  • scripts/decision_homes.toml
  • src/datamodel_code_generator/_client/security.py
  • src/datamodel_code_generator/_fastapi/plan.py
  • src/datamodel_code_generator/_fastapi/render.py
  • src/datamodel_code_generator/_openapi_wire_plan.py
  • src/datamodel_code_generator/_target_contract.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.

Walkthrough

The pull request adds shared target-contract helpers for security declarations and unresolved references. The FastAPI planner, client security planner, and OpenAPI wire planner now use these helpers. Architecture documentation and decision-home records describe the contracts.

Changes: Shared security contract

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 an apiKey header 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: 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 changes: reading security requirements, resolving security schemes, and centralizing API-key placement.
Docstring Coverage Passed 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. 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 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.

Share

@koxudaxi
Koudai Aono (koxudaxi) marked this pull request as ready for review October 31, 2026 09:16
@koxudaxi Koudai Aono (koxudaxi) changed the title impl c20 4 Read security requirements, resolve security schemes and place API key credentials in one place each Oct 31, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 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-31T09:17:24.792361Z cf63a0d 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.

@codecov

codecov Bot commented Oct 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Oct 31, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 11.43%

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 improved benchmark
✅ 51 untouched benchmarks
⏩ 98 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_perf_load_yaml_openapi_large 39.1 ms 35.1 ms +11.43%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing impl-c20-4 (cf63a0d) with main (400d6c5)

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

@koxudaxi
Koudai Aono (koxudaxi) merged commit 562a5c2 into main Oct 31, 2026
164 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the impl-c20-4 branch October 31, 2026 09:47
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: 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

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

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