feat: auto-configure security from OpenAPI securitySchemes#340
Merged
jonaslagoni merged 23 commits intomainfrom Mar 13, 2026
Merged
feat: auto-configure security from OpenAPI securitySchemes#340jonaslagoni merged 23 commits intomainfrom
jonaslagoni merged 23 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
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>
src/codegen/generators/typescript/channels/protocols/http/fetch.ts
Outdated
Show resolved
Hide resolved
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>
The init command tests were failing on CI because Node.js deprecation warnings (e.g., punycode module) were being captured in stderr, causing assertions expecting empty stderr to fail. Added a helper function isStderrEmpty() that filters out known Node.js deprecation warnings, making the tests more robust across different Node.js versions and environments. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fixes linting errors in test/commands/init.spec.ts where if statements were missing curly braces around their single-line return statements. 🤖 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
Scope names from OpenAPI specs are now escaped using escapeStringForCodeGen to prevent */ sequences from prematurely closing JSDoc comments in generated TypeScript code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Escape \n and \r characters to prevent syntax errors in generated TypeScript when OpenAPI spec values contain newlines (e.g., via YAML multi-line strings). 🤖 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.
Contributor
Author
|
🎉 This PR is included in version 0.68.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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 client authentication types and helper logic (OAuth2 flows, API key placement/defaults), which can alter generated output and runtime behavior for existing users.
Overview
TypeScript OpenAPI
http_clientcodegen now inspects the OpenAPI document’s security definitions and generates auth configuration/types based on the spec, rather than always emitting the full set.This adds
extractSecuritySchemes(OpenAPI 3.x + Swagger 2.0) and a new HTTP security rendering layer that conditionally emitsAuthConfigvariants, OAuth2 helpers/stubs behindAUTH_FEATURES, and API-key defaults (includingcookieplacement) while refactoring the HTTP protocol generator intoclient.ts+common-types.ts+security.ts. Tests/snapshots/runtime fixtures are updated and new unit tests cover security extraction and selective auth-type generation.Written by Cursor Bugbot for commit 5d997f3. This will update automatically on new commits. Configure here.