Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Dec 8, 2025

Description

Link to Devin run: https://app.devin.ai/sessions/04420b83e4c94f05bf2969c09e2c1722
Requested by: Niels Swimberghe (@Swimburger)

Adds a new anyAuth config option to the TypeScript SDK generator. When set to v2, users explicitly choose the auth type via a discriminated union with a type field, instead of the default v1 behavior where the SDK tries each auth method and catches errors.

Changes Made

  • Added anyAuth: "v1" | "v2" config option to TypescriptCustomConfigSchema
  • Created AnyAuthV2ProviderGenerator and AnyAuthV2ProviderInstance classes
  • Updated BaseClientTypeGenerator to generate AnyAuthProvider.AuthOptions when anyAuth: v2
  • Updated AuthProvidersGenerator to support the new "anyAuthV2" auth scheme type
  • Added seed test fixture any-auth/discriminated-union-auth with anyAuth: v2 config
  • Added changelog entry for v3.38.0

Example usage with anyAuth: v2:

# In generators.yml
config:
  anyAuth: v2
const client = new Client({
  auth: {
    type: "Bearer",
    token: "YOUR_BEARER_TOKEN"
  }
});

const client = new Client({
  auth: {
    type: "OAuth",
    clientId: "...",
    clientSecret: "..."
  }
});

Updates since last revision

Addressed PR feedback to pass normalized options to all auth providers:

  • Changed constructor type from BaseClientOptions & AnyAuthProvider.AuthOptions to just BaseClientOptions (since BaseClientOptions already includes AuthOptions via intersection)
  • Use options.auth directly in switch statement - TypeScript narrows the type within each case
  • Pass { ...options, ...options.auth } to ALL auth providers (Bearer, Header, Basic, OAuth) - this flattens the auth fields to the top level, matching how providers are constructed in non-any-auth fixtures
  • Removed any cast in default case error message

Testing

  • Seed tests pass for any-auth fixture (all 3 configurations)
  • Lint checks pass
  • Unit tests added/updated

Human Review Checklist

  • Options spreading: Verify { ...options, ...options.auth } correctly flattens auth fields to top level for each provider type
  • Type compatibility: The spread object should satisfy each provider's Options type (which extends AuthOptions)
  • Undefined auth fallback: When auth is undefined, the constructor creates a NoOpAuthProvider delegate. Verify this is the desired behavior vs. throwing an error.
  • Discriminator values: The type field values (e.g., "Bearer", "ApiKey", "OAuth") are derived from the auth scheme key in the IR. Verify these match expected user-facing values.

…iminatedUnionAuth flag

Co-Authored-By: Niels Swimberghe <[email protected]>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@devin-ai-integration devin-ai-integration bot changed the title feat(ts-sdk): add discriminated union auth configuration via useDiscriminatedUnionAuth flag feat(typescript): add discriminated union auth configuration via useDiscriminatedUnionAuth flag Dec 8, 2025
…m config

- Change config from boolean useDiscriminatedUnionAuth to enum anyAuth (v1 | v2)
- Rename DiscriminatedUnionAuthProviderGenerator to AnyAuthV2ProviderGenerator
- Rename DiscriminatedUnionAuthProviderInstance to AnyAuthV2ProviderInstance
- Rename generated class from DiscriminatedUnionAuthProvider to AnyAuthProvider
- Update seed.yml to use anyAuth: v2 instead of useDiscriminatedUnionAuth: true
- Update versions.yml changelog to reflect the new config option

Co-Authored-By: Niels Swimberghe <[email protected]>
@devin-ai-integration devin-ai-integration bot changed the title feat(typescript): add discriminated union auth configuration via useDiscriminatedUnionAuth flag feat(typescript): add discriminated union auth configuration via anyAuth enum Dec 8, 2025
…s for v2 discriminated union auth

- Remove imports for individual auth providers in AnyAuthV2ProviderGenerator
- Create inline auth provider implementations in constructor instead of delegating to imported providers
- Add explicit return type annotation for getAuthRequest to fix TypeScript compilation
- Handle undefined auth parameter with NoOpAuthProvider fallback
- Use core.Supplier.get() for resolving auth values
- Add core import to generated AnyAuthProvider file

Co-Authored-By: Niels Swimberghe <[email protected]>
- Update AnyAuthV2ProviderGenerator to import and use existing auth provider classes (BearerAuthProvider, HeaderAuthProvider, OAuthAuthProvider)
- Change AnyAuthProvider constructor to accept full BaseClientOptions instead of just auth field
- Use adapter pattern: spread full options and override auth-specific fields when instantiating providers
- Fix OAuthAuthProviderGenerator canCreate method to accept Options & Partial<AuthOptions>
- Update BaseClientTypeGenerator to pass full options to AnyAuthProvider
- Generate individual auth providers for v2 (previously skipped)

Co-Authored-By: Niels Swimberghe <[email protected]>
…arrowing

Address PR feedback:
- Change constructor type from 'BaseClientOptions & AnyAuthProvider.AuthOptions' to just 'BaseClientOptions' (since BaseClientOptions already includes AuthOptions)
- Use options.auth directly in switch instead of extracting to local variable
- Pass options.auth directly to Bearer/Header providers (TypeScript narrows the type)
- Pass { ...options, ...options.auth } to OAuth provider
- Remove 'any' cast in default case error message

Co-Authored-By: Niels Swimberghe <[email protected]>
switch (options.auth.type) {
case "Bearer":
this.delegate = new BearerAuthProvider({ ...options, token: auth.token });
this.delegate = new BearerAuthProvider(options.auth);
Copy link
Collaborator

Choose a reason for hiding this comment

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

No, it should be new BearerAuthProvider(options);.
update the generators so they accept the normalized options, joined with the bearer specific auth.
Do the same for other schemes

…n AnyAuthProvider

Address PR feedback:
- Pass { ...options, ...options.auth } to all auth providers (Bearer, Header, Basic, OAuth)
- This flattens the auth fields to the top level, matching the expected Options type
- Consistent with how auth providers are constructed in non-any-auth fixtures

Co-Authored-By: Niels Swimberghe <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants