feat: auto-configure security from OpenAPI securitySchemes#340
Open
jonaslagoni wants to merge 11 commits intomainfrom
Open
feat: auto-configure security from OpenAPI securitySchemes#340jonaslagoni wants to merge 11 commits intomainfrom
jonaslagoni wants to merge 11 commits intomainfrom
Conversation
Resolves #337 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
✅ Deploy Preview for the-codegen-project canceled.
|
The HTTP runtime tests were using randomly generated ports which could cause EADDRINUSE errors when multiple tests ran in parallel and got the same random port. This fix: - Uses port 0 to let the OS assign an available port - Properly handles server errors with 'error' event listener - Passes the actual assigned port to test callbacks via a new parameter This ensures tests don't fail due to port collisions in CI. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
src/codegen/generators/typescript/channels/protocols/http/fetch.ts
Outdated
Show resolved
Hide resolved
… code - Added renderOAuth2Stubs() to generate type-safe stub functions when OAuth2 is not needed, ensuring TypeScript compilation succeeds - Changed fallback AuthConfig to use 'never' type instead of union of all auth types when no recognized security schemes exist - Added AUTH_FEATURES.oauth2 runtime guards to generated function code 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
src/codegen/generators/typescript/channels/protocols/http/fetch.ts
Outdated
Show resolved
Hide resolved
- Fix ApiKeyAuth default mismatch: generated interface docs and runtime now use consistent spec-derived defaults instead of hardcoded 'X-API-Key' - Eliminate redundant analyzeSecuritySchemes call by passing pre-computed requirements to renderSecurityTypes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
src/codegen/generators/typescript/channels/protocols/http/fetch.ts
Outdated
Show resolved
Hide resolved
Add escapeStringForCodeGen helper to escape special characters (backslashes, single quotes, backticks, dollar signs) in OpenAPI spec values before interpolating them into generated TypeScript. Prevents syntax errors when spec values contain characters like quotes in apiKeyName, tokenUrl, etc. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Addresses PR review comment about duplicated logic between renderApiKeyAuthInterface and API_KEY_DEFAULTS template interpolation. Both now call getApiKeyDefaults() to ensure consistency. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The generated code now uses 'api_key' as the default header name (extracted from the OpenAPI spec) instead of the generic 'X-API-Key'. Updated the runtime test to expect this correct header name and updated snapshots to reflect the new generated output. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add curly braces after if condition - Remove multiple spaces before inline comments 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #337
See implementation details in
.claude/thoughts/issue-337-autoconfigure-security-from-op-2026-03-08/plan.mdTest Plan
npm run prepare:prpasses🤖 Generated with Claude Code
Note
Medium Risk
Changes affect generated authentication types and request auth application (API key defaults/cookie support and conditional OAuth2 helpers), which could alter output contracts and runtime behavior for existing generated clients.
Overview
TypeScript OpenAPI channel generation now parses
securitySchemes/securityDefinitionsand passes them intorenderHttpCommonTypes, so generated clients only include the auth interfaces/union types actually used by the spec (while keeping a no-arg fallback that emits all types).The HTTP fetch generator adds spec-driven defaults and safety: API key auth now supports
cookieplacement and uses generatedAPI_KEY_DEFAULTS, OAuth2 helpers are emitted only when OAuth2/OpenID Connect schemes exist (otherwise type-safe stubs are generated) and all OAuth2 codepaths are runtime-guarded viaAUTH_FEATURES; generated doc comments also include spec-derived token/auth URLs and sample scopes with escaping to prevent codegen injection.Adds
src/codegen/inputs/openapi/security.tsplus comprehensive unit tests and updates snapshots/runtime tests to reflect the new generated output and dynamic test server ports.Written by Cursor Bugbot for commit a8a30cb. This will update automatically on new commits. Configure here.