Files
supabase/apps/docs/features/docs/Reference.api.utils.ts
T
Hieu b76d04d6a0 fix: read FGA permissions from openapi spec x-fga-permissions extension (#48181)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Follow up to https://github.com/supabase/platform/pull/35940, which
moved FGA permissions off security and onto the `x-fga-permissions`
extension.

This updates the docs reference component to read from the new field.



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* API documentation now supports displaying fine-grained access
permissions for endpoints.
* Endpoint security details are presented more consistently using the
documented permissions configuration.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-07-23 12:17:45 +07:00

201 lines
4.0 KiB
TypeScript

export interface IApiEndPoint {
id: string
path: string
method: 'get' | 'post' | 'put' | 'delete' | 'patch'
summary?: string
description?: string
deprecated?: boolean
parameters: Array<{
name: string
required: boolean
in: 'path' | 'query' | 'body'
description?: string
schema: ISchema
}>
requestBody?: {
required?: boolean
content: IApiRequestBody
}
responses: {
[key: string]: {
description: string
content?: IApiJsonDTO
}
}
tags?: Array<string>
security?: Array<ISecurityOption>
'x-oauth-scope'?: string
'x-allowed-plans'?: string[]
'x-fga-permissions'?: string[][]
}
export type ISchema =
| ISchemaString
| ISchemaInteger
| ISchemaObject
| ISchemaEnum
| ISchemaBoolean
| ISchemaNumber
| ISchemaFile
| ISchemaArray
| ISchemaAllOf
| ISchemaAnyOf
| ISchemaOneOf
interface ISchemaBase {
description?: string
example?: unknown
deprecated?: boolean
nullable?: boolean
}
interface ISchemaBoolean extends ISchemaBase {
type: 'boolean'
}
interface ISchemaInteger extends ISchemaBase {
type: 'integer'
minimum?: number
maximum?: number
}
interface ISchemaNumber extends ISchemaBase {
type: 'number'
minimum?: number
maximum?: number
}
interface ISchemaString extends ISchemaBase {
type: 'string'
minLength?: number
maxLength?: number
pattern?: string
}
interface ISchemaFile extends ISchemaBase {
type: 'file'
format?: 'binary'
}
interface ISchemaObject extends ISchemaBase {
type: 'object'
properties?: { [key: string]: ISchema }
additionalProperties?: ISchema
required?: Array<string>
}
interface ISchemaArray extends ISchemaBase {
type: 'array'
items: ISchema
}
interface ISchemaEnum extends ISchemaBase {
type: string
enum: Array<unknown>
}
interface ISchemaAllOf extends ISchemaBase {
allOf: Array<ISchema>
}
interface ISchemaAnyOf extends ISchemaBase {
anyOf: Array<ISchema>
}
interface ISchemaOneOf extends ISchemaBase {
oneOf: Array<ISchema>
}
interface IApiRequestBody extends IApiJsonDTO, IApiFormUrlEncodedDTO {}
interface IApiJsonDTO {
'application/json'?: {
schema: ISchema
}
}
interface IApiFormUrlEncodedDTO {
'application/x-www-form-urlencoded'?: {
schema: ISchema
}
}
type ISecurityOption = IBearerSecurity | IOAuth2Security | IFgaSecurity
interface IBearerSecurity {
bearer: []
}
interface IOAuth2Security {
oauth2: Array<'read' | 'write'>
}
interface IFgaSecurity {
fga_permissions: string[]
}
export function getTypeDisplayFromSchema(schema: ISchema) {
if ('allOf' in schema) {
if (schema.allOf.length === 1) {
return getTypeDisplayFromSchema(schema.allOf[0])
} else {
return {
displayName: 'all of the following options',
}
}
} else if ('oneOf' in schema) {
if (schema.oneOf.length === 1) {
return getTypeDisplayFromSchema(schema.oneOf[0])
} else {
return {
displayName: 'one of the following options',
}
}
} else if ('anyOf' in schema) {
if (schema.anyOf.length === 1) {
return getTypeDisplayFromSchema(schema.anyOf[0])
} else {
return {
displayName: 'any of the following options',
}
}
} else if ('enum' in schema) {
return {
displayName: 'enum',
}
} else if (schema.type === 'boolean') {
return {
displayName: 'boolean',
}
} else if (schema.type === 'integer') {
return {
displayName: 'integer',
}
} else if (schema.type === 'number') {
return {
displayName: 'number',
}
} else if (schema.type === 'string') {
return {
displayName: 'string',
}
} else if (schema.type === 'file') {
return {
displayName: 'file',
}
} else if (schema.type === 'array') {
return {
displayName: `Array<${getTypeDisplayFromSchema(schema.items).displayName}>`,
}
} else if (schema.type === 'object') {
return {
displayName: 'object',
}
}
// Default fallback for unhandled schema types
return {
displayName: 'unknown',
}
}