Files
Charis 6cde55ae3c feat(api-types): generate fga-requirements.ts from OpenAPI specs (#52093)
## What

Generates `packages/api-types/types/fga-requirements.ts`, a map from
`'METHOD /path'` to the FGA permission groups that endpoint requires,
from the `x-fga-permissions` annotations in the v1, v2, and platform
OpenAPI specs. Groups are OR-of-AND (a caller needs every permission in
at least one group) and are preserved verbatim. Keys are the path
literals passed to openapi-fetch, so later work can type-check
permission grants against fetch calls.

- `codegen:prod` and the production drift check
(`verify-production-types`) now generate and compare the new file.
- Local `codegen` also generates it, from the local API
(`LOCAL_API_URL`, defaults to `http://localhost:8080`).
- Permission IDs are validated against the platform spec's
`CreateScopedAccessTokenBody.permissions` enum. Generation fails on
malformed annotations, empty groups, unknown IDs, or an endpoint
annotated in two specs. An empty annotation (`[]`) is treated as ungated
and omitted.
- The drift-check workflow now also runs when
`packages/api-types/scripts/` changes, so generator changes without
regenerated output are caught.
- Exported from `api-types` as `fgaRequirements`, with `FgaRequirements`
and `FgaGuardedEndpoint` types.

No Studio changes.

## Testing

- `pnpm --filter=api-types test`
- `pnpm --filter=api-types codegen:prod` regenerates the committed file
with no diff.

Resolves FE-4686
2026-10-21 14:17:02 -04:00

42 lines
1.5 KiB
TypeScript

import type {
components as apiV1Components,
operations as apiV1Operations,
paths as apiV1Paths,
} from './types/api-v1'
import type {
components as apiV2Components,
operations as apiV2Operations,
paths as apiV2Paths,
} from './types/api-v2'
import type {
components as platformComponents,
operations as platformOperations,
paths as platformPaths,
} from './types/platform'
export type { webhooks, $defs } from './types/api-v2'
export interface paths extends apiV2Paths, apiV1Paths, platformPaths {}
export interface operations extends apiV2Operations, apiV1Operations, platformOperations {}
export interface components {
schemas: apiV2Components['schemas'] & apiV1Components['schemas'] & platformComponents['schemas']
responses: apiV2Components['responses'] &
apiV1Components['responses'] &
platformComponents['responses']
parameters: apiV2Components['parameters'] &
apiV1Components['parameters'] &
platformComponents['parameters']
requestBodies: apiV2Components['requestBodies'] &
apiV1Components['requestBodies'] &
platformComponents['requestBodies']
headers: apiV2Components['headers'] & apiV1Components['headers'] & platformComponents['headers']
pathItems: apiV2Components['pathItems'] &
apiV1Components['pathItems'] &
platformComponents['pathItems']
}
export type { platformComponents, apiV1Components, apiV2Components }
export { fgaRequirements } from './types/fga-requirements'
export type { FgaRequirements, FgaGuardedEndpoint } from './types/fga-requirements'