-
Notifications
You must be signed in to change notification settings - Fork 271
feat(typescript): add discriminated union auth configuration via anyAuth enum #11081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(typescript): add discriminated union auth configuration via anyAuth enum #11081
Conversation
…iminatedUnionAuth flag Co-Authored-By: Niels Swimberghe <[email protected]>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
generators/typescript-v2/ast/src/custom-config/TypescriptCustomConfigSchema.ts
Outdated
Show resolved
Hide resolved
...ript/sdk/client-class-generator/src/auth-provider/DiscriminatedUnionAuthProviderGenerator.ts
Outdated
Show resolved
Hide resolved
...ript/sdk/client-class-generator/src/auth-provider/DiscriminatedUnionAuthProviderGenerator.ts
Outdated
Show resolved
Hide resolved
…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]>
seed/ts-sdk/any-auth/discriminated-union-auth/src/auth/AnyAuthProvider.ts
Outdated
Show resolved
Hide resolved
seed/ts-sdk/any-auth/discriminated-union-auth/src/auth/AnyAuthProvider.ts
Outdated
Show resolved
Hide resolved
seed/ts-sdk/any-auth/discriminated-union-auth/src/auth/AnyAuthProvider.ts
Outdated
Show resolved
Hide resolved
seed/ts-sdk/any-auth/discriminated-union-auth/src/auth/AnyAuthProvider.ts
Outdated
Show resolved
Hide resolved
seed/ts-sdk/any-auth/discriminated-union-auth/src/auth/AnyAuthProvider.ts
Outdated
Show resolved
Hide resolved
…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]>
seed/ts-sdk/any-auth/discriminated-union-auth/src/auth/AnyAuthProvider.ts
Outdated
Show resolved
Hide resolved
- 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]>
seed/ts-sdk/any-auth/discriminated-union-auth/src/auth/AnyAuthProvider.ts
Outdated
Show resolved
Hide resolved
seed/ts-sdk/any-auth/discriminated-union-auth/src/auth/AnyAuthProvider.ts
Outdated
Show resolved
Hide resolved
seed/ts-sdk/any-auth/discriminated-union-auth/src/auth/AnyAuthProvider.ts
Outdated
Show resolved
Hide resolved
seed/ts-sdk/any-auth/discriminated-union-auth/src/auth/AnyAuthProvider.ts
Outdated
Show resolved
Hide resolved
seed/ts-sdk/any-auth/discriminated-union-auth/src/auth/AnyAuthProvider.ts
Outdated
Show resolved
Hide resolved
…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); |
There was a problem hiding this comment.
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]>
Description
Link to Devin run: https://app.devin.ai/sessions/04420b83e4c94f05bf2969c09e2c1722
Requested by: Niels Swimberghe (@Swimburger)
Adds a new
anyAuthconfig option to the TypeScript SDK generator. When set tov2, users explicitly choose the auth type via a discriminated union with atypefield, instead of the defaultv1behavior where the SDK tries each auth method and catches errors.Changes Made
anyAuth: "v1" | "v2"config option toTypescriptCustomConfigSchemaAnyAuthV2ProviderGeneratorandAnyAuthV2ProviderInstanceclassesBaseClientTypeGeneratorto generateAnyAuthProvider.AuthOptionswhenanyAuth: v2AuthProvidersGeneratorto support the new "anyAuthV2" auth scheme typeany-auth/discriminated-union-authwithanyAuth: v2configExample usage with
anyAuth: v2:Updates since last revision
Addressed PR feedback to pass normalized options to all auth providers:
BaseClientOptions & AnyAuthProvider.AuthOptionsto justBaseClientOptions(sinceBaseClientOptionsalready includesAuthOptionsvia intersection)options.authdirectly in switch statement - TypeScript narrows the type within each case{ ...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 fixturesanycast in default case error messageTesting
any-authfixture (all 3 configurations)Human Review Checklist
{ ...options, ...options.auth }correctly flattens auth fields to top level for each provider typeOptionstype (which extendsAuthOptions)authis undefined, the constructor creates aNoOpAuthProviderdelegate. Verify this is the desired behavior vs. throwing an error.typefield values (e.g., "Bearer", "ApiKey", "OAuth") are derived from the auth scheme key in the IR. Verify these match expected user-facing values.