Skip to content

feat: auto-configure security from OpenAPI securitySchemes#340

Merged
jonaslagoni merged 23 commits intomainfrom
issue-337-autoconfigure-security-from-op
Mar 13, 2026
Merged

feat: auto-configure security from OpenAPI securitySchemes#340
jonaslagoni merged 23 commits intomainfrom
issue-337-autoconfigure-security-from-op

Conversation

@jonaslagoni
Copy link
Copy Markdown
Contributor

@jonaslagoni jonaslagoni commented Mar 8, 2026

Summary

Resolves #337

See implementation details in .claude/thoughts/issue-337-autoconfigure-security-from-op-2026-03-08/plan.md

Test Plan

  • All unit tests pass
  • All runtime tests pass
  • npm run prepare:pr passes

🤖 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_client codegen 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 emits AuthConfig variants, OAuth2 helpers/stubs behind AUTH_FEATURES, and API-key defaults (including cookie placement) while refactoring the HTTP protocol generator into client.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.

Resolves #337

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jonaslagoni jonaslagoni requested a review from ALagoni97 as a code owner March 8, 2026 21:08
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
the-codegen-project Ready Ready Preview, Comment Mar 12, 2026 9:58pm
the-codegen-project-mcp Ready Ready Preview, Comment Mar 12, 2026 9:58pm

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 8, 2026

Deploy Preview for the-codegen-project canceled.

Name Link
🔨 Latest commit 5d997f3
🔍 Latest deploy log https://app.netlify.com/projects/the-codegen-project/deploys/69b3368eb8d93c00094634c9

@jonaslagoni jonaslagoni changed the title feat: Auto-configure security from OpenAPI securitySchemes feat: auto-configure security from OpenAPI securitySchemes Mar 8, 2026
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>
jonaslagoni and others added 2 commits March 9, 2026 08:54
… 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>
- 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>
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>
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>
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>
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jonaslagoni jonaslagoni merged commit cf6ae51 into main Mar 13, 2026
22 checks passed
@jonaslagoni jonaslagoni deleted the issue-337-autoconfigure-security-from-op branch March 13, 2026 14:38
@jonaslagoni
Copy link
Copy Markdown
Contributor Author

🎉 This PR is included in version 0.68.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-configure security from OpenAPI securitySchemes

1 participant