Support non primitive examples in OpenAPI block (#2775)

This commit is contained in:
Nolann B.
2025-02-03 17:07:29 +01:00
committed by GitHub
parent 9e18ae6587
commit 2f73db785e
3 changed files with 11 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@gitbook/react-openapi': patch
---
Support non primitive examples in OpenAPI block
@@ -176,7 +176,7 @@
.openapi-schema-example,
.openapi-schema-pattern {
@apply prose-sm mt-2 text-tint-strong;
@apply prose-sm mt-1 text-tint-strong;
}
/** Authentication */
+5 -3
View File
@@ -51,7 +51,9 @@ export function OpenAPISchemaProperty(
return (
typeof schema.example === 'string' ||
typeof schema.example === 'number' ||
typeof schema.example === 'boolean'
typeof schema.example === 'boolean' ||
(Array.isArray(schema.example) && schema.example.length > 0) ||
(typeof schema.example === 'object' && Object.keys(schema.example).length > 0)
);
};
return (
@@ -100,9 +102,9 @@ export function OpenAPISchemaProperty(
/>
) : null}
{shouldDisplayExample(schema) ? (
<span className="openapi-schema-example">
<div className="openapi-schema-example">
Example: <code>{stringifyOpenAPI(schema.example)}</code>
</span>
</div>
) : null}
{schema.pattern ? (
<div className="openapi-schema-pattern">