feat(sdk): expose securitySchemes key on Auth when schemes collide#3935
Conversation
When an OpenAPI spec defines two or more `components.securitySchemes` entries whose generated `Auth` shape would otherwise be identical (e.g. two `http`/`bearer` schemes used by different operations), the SDK now emits the `components.securitySchemes` key as `Auth.key` so the runtime auth callback can disambiguate which token to return. Schemes with unique signatures are unchanged. Fixes hey-api#3817. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
|
|
@matthewjamesadam is attempting to deploy a commit to the Hey API Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 23d908a The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Important
securitySchemeSignature produces false collisions for oauth2 schemes with only authorizationCode flow, causing unnecessary key fields on otherwise unique schemes.
Reviewed changes — collision detection for security schemes that would emit identical Auth shapes, exposing the scheme key only when disambiguation is needed.
- Add
computeAmbiguousSecurityKeysutility — canonical signature-based collision detection in@hey-api/shared - Thread
ambiguousSecurityKeysthrough all three OpenAPI version parsers — attacheskeyto IR security objects only for colliding schemes - Forward
keyin SDK auth plugin — passes the scheme name through to generatedAuthobjects - Update
Authinterface JSDoc — documents the newkeyfield in client-core bundle - Add test fixtures and snapshots —
security-http-bearer-duplicatespecs for 3.0.x and 3.1.x
Kimi K2 | 𝕏
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3935 +/- ##
==========================================
+ Coverage 37.36% 37.40% +0.04%
==========================================
Files 653 654 +1
Lines 22430 22456 +26
Branches 6520 6531 +11
==========================================
+ Hits 8381 8400 +19
- Misses 11391 11397 +6
- Partials 2658 2659 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@hey-api/codegen-core
@hey-api/json-schema-ref-parser
@hey-api/nuxt
@hey-api/openapi-ts
@hey-api/shared
@hey-api/spec-types
@hey-api/types
@hey-api/vite-plugin
commit: |
mrlubos
left a comment
There was a problem hiding this comment.
@matthewjamesadam this one also looks good, thank you!

Summary
Fixes #3817.
When an OpenAPI spec defines two or more
components.securitySchemesentries whose generatedAuthshape would otherwise be identical (e.g. twohttp/bearerschemes used by different operations), the SDK now emits thecomponents.securitySchemeskey asAuth.keyso the runtime auth callback can disambiguate which token to return. Schemes with unique signatures are unchanged — preserving the "no redundant info" property we discussed in the issue thread (#3817 (comment)).How collision detection works
A new helper in
@hey-api/shared(packages/shared/src/openApi/shared/utils/security.ts) computes a canonical signature for each scheme (e.g.http:bearer,apiKey:header:X-Token) that mirrors what the SDK plugin emits ontoAuth.computeAmbiguousSecurityKeysbuckets everycomponents.securitySchemesentry by that signature and returns the set of keys whose bucket has size ≥ 2. The parser threads that set throughparsePathOperation/parseWebhookOperationfor all three OpenAPI versions (2.0, 3.0, 3.1) and attacheskeyto the IR security object only for ambiguous schemes. The SDK plugin (auth.ts) is a pass-through.Generated SDK before/after
For the new test fixture
specs/3.1.x/security-http-bearer-duplicate.json(twohttp/bearerschemesbearerAuth+refreshAuthplus a uniquehttp/basicbasicAuth):All existing
security-*snapshots have unchangedsdk.gen.tsoutput; only theAuthinterface JSDoc inauth.gen.tschanged.Test plan
pnpm exec vitest run --project @hey-api/shared --project @test/openapi-ts— 818 passed (added scenarios for 3.0.x + 3.1.x inopenapi-ts-tests, plus unit tests for the new helper and the 3.1.x parser)pnpm ty @hey-api/shared --filter @hey-api/openapi-ts --filter @test/openapi-ts— cleanpnpm lint— 0 errors🤖 Generated with Claude Code