diff --git a/src/components/ApiDocs/Schema.astro b/src/components/ApiDocs/Schema.astro index cffbb092..a0e9a15c 100644 --- a/src/components/ApiDocs/Schema.astro +++ b/src/components/ApiDocs/Schema.astro @@ -14,6 +14,23 @@ const isNonArraySchemaObject = ( ): object is OpenAPIV3_1.NonArraySchemaObject => !!object && !("items" in object); +const getRenderableAttributesSchema = ( + object: OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject | undefined, +): OpenAPIV3_1.SchemaObject | null => { + if (!object) return null; + + const schema = resolveSchema(object); + const hasProperties = Object.keys(schema.properties || {}).length > 0; + + if (hasProperties) return schema; + + if (schema.type === "array" && "items" in schema) { + return getRenderableAttributesSchema(schema.items); + } + + return null; +}; + export interface Props { kind: string; schema: OpenAPIV3_1.SchemaObject; @@ -55,12 +72,20 @@ const schema = resolveSchema(obj); } {!nested && !collapsable &&

{schema.title || kind}

} { - schema.type === "array" && "items" in schema && ( -
- - -
- ) + schema.type === "array" && + "items" in schema && + (() => { + const attributesSchema = getRenderableAttributesSchema(schema.items); + + return ( +
+ + {attributesSchema && ( + + )} +
+ ); + })() }