Skip to content

Commit 2f73db7

Browse files
authored
Support non primitive examples in OpenAPI block (#2775)
1 parent 9e18ae6 commit 2f73db7

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

.changeset/stupid-points-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/react-openapi': patch
3+
---
4+
5+
Support non primitive examples in OpenAPI block

packages/gitbook/src/components/DocumentView/OpenAPI/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176

177177
.openapi-schema-example,
178178
.openapi-schema-pattern {
179-
@apply prose-sm mt-2 text-tint-strong;
179+
@apply prose-sm mt-1 text-tint-strong;
180180
}
181181

182182
/** Authentication */

packages/react-openapi/src/OpenAPISchema.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ export function OpenAPISchemaProperty(
5151
return (
5252
typeof schema.example === 'string' ||
5353
typeof schema.example === 'number' ||
54-
typeof schema.example === 'boolean'
54+
typeof schema.example === 'boolean' ||
55+
(Array.isArray(schema.example) && schema.example.length > 0) ||
56+
(typeof schema.example === 'object' && Object.keys(schema.example).length > 0)
5557
);
5658
};
5759
return (
@@ -100,9 +102,9 @@ export function OpenAPISchemaProperty(
100102
/>
101103
) : null}
102104
{shouldDisplayExample(schema) ? (
103-
<span className="openapi-schema-example">
105+
<div className="openapi-schema-example">
104106
Example: <code>{stringifyOpenAPI(schema.example)}</code>
105-
</span>
107+
</div>
106108
) : null}
107109
{schema.pattern ? (
108110
<div className="openapi-schema-pattern">

0 commit comments

Comments
 (0)