Skip to content

fix(codegen): auth signs in an operation whose spec says security: [] - #634

Merged
leemour merged 1 commit into
mainfrom
fix/codegen-empty-security
Nov 17, 2026
Merged

leemour merged 1 commit into
mainfrom
fix/codegen-empty-security

Conversation

@leemour

@leemour leemour commented Nov 17, 2026

Copy link
Copy Markdown
Member

Task

With auth (the CLI's own sign-in scheme), generate kept an operation's security: []. cli-core's authHeader reads an empty list as "no sign-in", so the request went out without the key.

Why

hubspot-cli 0.1.0 sent 115 api operations (deals-get, contacts-list…) without the key, and HubSpot answered 401. HubSpot's object specs (calls, companies, contacts, deals, emails, leads, meetings, notes, tasks, tickets) put security: [] on those operations themselves; the document has no top-level security. hubspot-cli works around it in src/config.ts.

The rule

With auth, an operation keeps its own security only when it signs in by auth's schemes: at least one non-empty requirement, and every name is one of auth's. [], [{}] and requirements naming the source's own schemes get auth's security. An optional sign-in ([{}, { token: [] }]) is kept. Without auth, [] still means "no sign-in".

Why not keep [] for a truly public call (a health check, a token exchange):

  • Passing auth already says the source's sign-in is wrong. An empty list from that same source is no more trustworthy.
  • The two mistakes are not equal. A key sent to a public call is almost always ignored. A key left off a private call always fails.
  • No CLI needs a public call under auth today: Yandex Disk, the other user of auth, has no operation-level security.

If a CLI ever needs one, it needs a new option. Override has no security field, and overrides run before auth. Not built now.

"Signs in" reuses signInRequirements, so it means the same here as in the fake API and in cli-core.

What

  • src/codegen/pipeline.ts: applyAuth keeps an operation's security only when it signs in by auth's schemes.
  • Tests: a new case in codegen.test.ts for [], [{}], a source scheme, an auth scheme and an optional sign-in, with and without auth. The existing openapi.test.ts case that pinned the old behaviour (/health keeping []) now expects it replaced.
  • docs/standards/kit-surface.md and CHANGELOG.md (Unreleased, Fixed).

Testing

  • pnpm vitest run src/codegen: 119 passed. The two affected tests fail on the old pipeline.ts.
  • pnpm typecheck, pnpm biome check . (no new warnings), pnpm docs:check: pass.

Follow-up for hubspot-cli after it bumps to the release with this fix: drop the security workaround in src/config.ts, and invert the assertion in src/api.test.ts:94 that expects an operation with an empty security.

🤖 Generated with Claude Code

With `auth` (the CLI's own sign-in scheme), `generate` kept an operation's
`security: []`. cli-core's authHeader reads that as "no sign-in", so the
call went out without the key. hubspot-cli 0.1.0 sent 115 api calls
(deals-get, contacts-list...) that way and HubSpot answered 401: its object
specs put `security: []` on those operations.

Rule: with `auth`, an operation keeps its own `security` only when it signs
in by auth's schemes (at least one non-empty requirement, every name one of
auth's). `[]`, `[{}]` and requirements naming the source's own schemes fall
back to auth's `security`. Passing `auth` already says the source's sign-in
is wrong; a key sent to a public call is ignored, a key left off a private
call always fails. No CLI needs a public call under auth today (Yandex Disk
has no operation-level security). If one ever does, it needs a new option:
`Override` has no security field, and overrides run before `auth`.
Without `auth`, `[]` still means "no sign-in".

The rule reuses signInRequirements, so "signs in" means the same here as in
the fake API and cli-core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leemour
leemour merged commit ba7325e into main Nov 17, 2026
10 checks passed
@leemour
leemour deleted the fix/codegen-empty-security branch November 17, 2026 21:00
@leemour leemour mentioned this pull request Nov 17, 2026
leemour added a commit that referenced this pull request Nov 17, 2026
Dates the release as 0.115.0, carrying #635 (the `graphql` spec kind,
Added → minor) and #634 (`auth` signs in an operation whose spec says
`security: []`). Only package.json and the CHANGELOG change;
`bin/release` publishes it after the merge.

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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant