diff --git a/.changeset/stupid-points-chew.md b/.changeset/stupid-points-chew.md new file mode 100644 index 000000000..14f33a173 --- /dev/null +++ b/.changeset/stupid-points-chew.md @@ -0,0 +1,5 @@ +--- +'@gitbook/react-openapi': patch +--- + +Support non primitive examples in OpenAPI block diff --git a/packages/gitbook/src/components/DocumentView/OpenAPI/style.css b/packages/gitbook/src/components/DocumentView/OpenAPI/style.css index 9f2d9289f..616d1f97d 100644 --- a/packages/gitbook/src/components/DocumentView/OpenAPI/style.css +++ b/packages/gitbook/src/components/DocumentView/OpenAPI/style.css @@ -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 */ diff --git a/packages/react-openapi/src/OpenAPISchema.tsx b/packages/react-openapi/src/OpenAPISchema.tsx index e914e3fa1..81850da6e 100644 --- a/packages/react-openapi/src/OpenAPISchema.tsx +++ b/packages/react-openapi/src/OpenAPISchema.tsx @@ -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) ? ( - +
Example: {stringifyOpenAPI(schema.example)} - +
) : null} {schema.pattern ? (