Skip to content

feat: add automatic project setup detection to generator lifecycle#341

Closed
jonaslagoni wants to merge 13 commits into
mainfrom
issue-336-add-automatic-project-setup-de
Closed

feat: add automatic project setup detection to generator lifecycle#341
jonaslagoni wants to merge 13 commits into
mainfrom
issue-336-add-automatic-project-setup-de

Conversation

@jonaslagoni
Copy link
Copy Markdown
Contributor

@jonaslagoni jonaslagoni commented Mar 9, 2026

Summary

Resolves #336

See implementation details in .claude/thoughts/issue-336-add-automatic-project-setup-de-2026-03-09/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 generator defaults and alters generated TypeScript output (imports and auth type shapes), which may affect downstream builds or snapshots even though behavior is gated by explicit config and covered by tests.

Overview
Adds automatic importExtension detection during realizeGeneratorContext by scanning nearby tsconfig.json/package.json (including JSONC, directory traversal, and extends resolution) and only applying it when the user hasn’t explicitly set importExtension.

Enhances the TypeScript OpenAPI HTTP client generator to parse OpenAPI/Swagger security schemes and generate only the relevant auth types (and doc defaults like apiKey name/location and OAuth URLs/scopes), with runtime guards/stubs so unused OAuth2 helpers aren’t emitted/called.

Updates snapshots, adds comprehensive unit/integration tests for detection and security extraction, and pins runtime test configs to importExtension: 'none' to keep Jest/SWC behavior stable.

Written by Cursor Bugbot for commit c2e7b64. This will update automatically on new commits. Configure here.

jonaslagoni and others added 4 commits March 8, 2026 22:08
Resolves #337

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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>
… 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>
Resolves #336

🤖 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 9, 2026 08:31
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 9, 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 9, 2026 10:23am
the-codegen-project-mcp Ready Ready Preview, Comment Mar 9, 2026 10:23am

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 9, 2026

Deploy Preview for the-codegen-project canceled.

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

Comment thread src/codegen/detection.ts
Comment thread src/codegen/inputs/openapi/security.ts Outdated
Comment thread src/codegen/generators/typescript/channels/types.ts Outdated
- Fix stripJsonComments to properly handle URLs with // inside JSON strings
  by using a state machine that tracks string boundaries
- Remove unused getOperationSecurityRequirements export (dead code)
- Remove unused securitySchemes field from RenderHttpParameters type

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jonaslagoni jonaslagoni changed the title feat: Add automatic project setup detection to generator lifecycle feat: add automatic project setup detection to generator lifecycle Mar 9, 2026
Extract helper functions to reduce cognitive complexity from 34 to below 15.
Use string.charAt() instead of bracket notation to avoid object injection
sink warnings.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment thread src/codegen/inputs/openapi/security.ts Outdated
Comment thread src/codegen/generators/typescript/channels/protocols/http/fetch.ts Outdated
Comment thread src/codegen/detection.ts
- Remove unused OpenAPIOperation type from security.ts (dead code)
- Eliminate redundant analyzeSecuritySchemes call in fetch.ts by passing pre-computed requirements
- Add trailing comma handling to stripJsonComments for JSONC compatibility

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment thread src/codegen/detection.ts Outdated
Comment thread src/codegen/detection.ts
- detection.ts: Fix malformed tsconfig fallback - stop searching parent
  directories when a tsconfig.json is found but fails to parse
- detection.ts: Fix trailing comma regex to respect JSON string boundaries
  by implementing string-aware removal instead of blanket regex

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment thread src/codegen/detection.ts
The TsConfig interface now accepts `extends` as either `string | string[]`
to support TypeScript 5.0+ config composition. The `resolveTsConfigExtends`
function iterates through array extends and merges configs in order.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The new automatic importExtension detection feature was incorrectly
choosing '.js' for runtime tests because it found the root tsconfig
with moduleResolution: node16. Since Jest/SWC handles module resolution
without needing file extensions, explicitly set importExtension: 'none'
in all runtime test codegen configs.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment thread src/codegen/detection.ts
Add fileWasFound flag to stop searching parent directories when a
package.json is found but fails to parse, matching the behavior of
findAndParseTsConfig. This prevents incorrect importExtension detection
when a project's package.json has a syntax error.

🤖 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>
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 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread src/codegen/detection.ts
Logger.debug(`Could not resolve tsconfig extends: ${error}`);
return tsconfig;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Circular tsconfig extends causes unguarded stack overflow

Low Severity

resolveTsConfigExtends recursively follows extends chains without any depth limit or cycle detection. If a tsconfig file has a circular extends reference (e.g., A extends B, B extends A), this will recurse until a stack overflow. While the outer try/catch can catch the RangeError, deep recursion before the crash may degrade performance, and the eventual recovery discards all parent config resolution.

Fix in Cursor Fix in Web

Comment thread src/codegen/detection.ts

// Remove trailing commas with string-aware logic
return removeTrailingCommas(state.result);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Custom JSONC parser duplicates well-tested library functionality

Low Severity

The stripJsonComments and removeTrailingCommas functions span ~150 lines with 8 helper functions, reimplementing JSONC parsing that battle-tested libraries like strip-json-comments or jsonc-parser handle comprehensively. This hand-rolled parser processes user-facing configuration files (tsconfig.json), where subtle edge cases in comment/string boundary tracking could lead to silent misparses. The complexity (mutable state object, multiple interacting state machines) increases maintenance burden and risk.

Fix in Cursor Fix in Web

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add automatic project setup detection to generator lifecycle

1 participant