Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: display request body Array<object> schema/fields in Management API Reference (#49575)

Samir Ketema478d95b35c34
diff --git a/apps/docs/features/docs/Reference.ui.tsx b/apps/docs/features/docs/Reference.ui.tsx
index 2cac82a4c0c..c8a2ee5704b 100644
--- a/apps/docs/features/docs/Reference.ui.tsx
+++ b/apps/docs/features/docs/Reference.ui.tsx
@@ -381,6 +381,14 @@ interface ApiOperationRequestBodyDetailsInternalProps extends HTMLAttributes<HTM
schema: ISchema
}
+// Some specs have allOf/anyOf/oneOf as a single schema object instead of an
+// array. Wrap it so it still renders instead of crashing or disappearing.
+function asSchemaArray(value: unknown): Array<any> {
+ if (Array.isArray(value)) return value
+ if (value && typeof value === 'object') return [value]
+ return []
+}
+
function ApiOperationRequestBodyDetailsInternal({
schema,
...props
@@ -389,7 +397,7 @@ function ApiOperationRequestBodyDetailsInternal({
return (
<>
<span className="font-mono text-sm font-medium text-foreground">All of the following:</span>
- {schema.allOf.map((option, index) => (
+ {asSchemaArray(schema.allOf).map((option, index) => (
<ApiSchemaParamSubdetails key={index} schema={option} />
))}
</>
@@ -398,7 +406,7 @@ function ApiOperationRequestBodyDetailsInternal({
return (
<>
<span className="font-mono text-sm font-medium text-foreground">Any of the following:</span>
- {schema.anyOf.map((option, index) => (
+ {asSchemaArray(schema.anyOf).map((option, index) => (
<ApiSchemaParamSubdetails key={index} schema={option} />
))}
</>
@@ -407,7 +415,7 @@ function ApiOperationRequestBodyDetailsInternal({
return (
<>
<span className="font-mono text-sm font-medium text-foreground">One of the following:</span>
- {schema.oneOf.map((option, index) => (
+ {asSchemaArray(schema.oneOf).map((option, index) => (
<ApiSchemaParamSubdetails key={index} schema={option} />
))}
</>
@@ -431,10 +439,11 @@ function ApiOperationRequestBodyDetailsInternal({
return (
<>
<span className="font-mono text-sm font-medium text-foreground">{`Array of ${displayName}`}</span>
- {!(
- 'type' in schema.items &&
- ['string', 'boolean', 'number', 'integer'].includes(schema.items.type)
- ) && <ApiSchemaParamSubdetails className="mt-4" schema={schema.items} />}
+ {schema.items &&
+ !(
+ 'type' in schema.items &&
+ ['string', 'boolean', 'number', 'integer'].includes(schema.items.type)
+ ) && <ApiSchemaParamSubdetails className="mt-4" schema={schema.items} />}
</>
)
} else if (schema.type === 'object') {
@@ -469,13 +478,14 @@ export function ApiSchemaParamSubdetails({
(schema.type === 'string' &&
!('minLength' in schema || 'maxLength' in schema || 'pattern' in schema)) ||
(schema.type === 'array' &&
+ schema.items &&
'type' in schema.items &&
['boolean', 'number', 'integer', 'string', 'file'].includes(schema.items.type)))
) {
return null
}
- const subContent =
+ const rawSubContent =
'enum' in schema
? schema.enum
: 'anyOf' in schema
@@ -492,6 +502,7 @@ export function ApiSchemaParamSubdetails({
value: schema[key],
}))
: []
+ const subContent = asSchemaArray(rawSubContent)
return (
<Collapsible>
@@ -530,8 +541,24 @@ export function ApiSchemaParamSubdetails({
</CollapsibleTrigger>
<CollapsibleContent>
{'type' in schema && schema.type === 'object' ? (
- <div className={cn('border-b border-x border-fault', 'rounded-b-lg', 'p-5')}>
- <ApiSchema schema={schema} />
+ <div className={cn('border-b border-x border-default', 'rounded-b-lg')}>
+ <div className="p-5 border-b border-default">
+ <ApiSchema schema={schema} />
+ </div>
+ <ApiOperationRequestBodyDetailsInternal schema={schema} className="px-5" />
+ </div>
+ ) : 'type' in schema &&
+ schema.type === 'array' &&
+ 'items' in schema &&
+ schema.items &&
+ typeof schema.items === 'object' &&
+ 'type' in schema.items &&
+ schema.items.type === 'object' ? (
+ <div className={cn('border-b border-x border-default', 'rounded-b-lg')}>
+ <div className="p-5 border-b border-default">
+ <ApiSchema schema={schema} />
+ </div>
+ <ApiOperationRequestBodyDetailsInternal schema={schema.items} className="px-5" />
</div>
) : (
<ul className={cn('border-b border-x border-default', 'rounded-b-lg')}>