Fix OpenAPI example (#2944)

This commit is contained in:
Greg Bergé
2025-03-07 17:54:35 +01:00
committed by GitHub
parent 3e1592e16b
commit f574858b9b
3 changed files with 9 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@gitbook/react-openapi': patch
---
Fix OpenAPI example display error
+2 -2
View File
@@ -217,7 +217,7 @@ function OpenAPISchemaPresentation(props: { property: OpenAPISchemaPropertyEntry
propertyName={propertyName}
required={required}
/>
{schema['x-deprecated-sunset'] ? (
{typeof schema['x-deprecated-sunset'] === 'string' ? (
<div className="openapi-deprecated-sunset openapi-schema-description openapi-markdown">
Sunset date:{' '}
<span className="openapi-deprecated-sunset-date">
@@ -228,7 +228,7 @@ function OpenAPISchemaPresentation(props: { property: OpenAPISchemaPropertyEntry
{description ? (
<Markdown source={description} className="openapi-schema-description" />
) : null}
{example ? (
{typeof example === 'string' ? (
<div className="openapi-schema-example">
Example: <code>{example}</code>
</div>
+2 -2
View File
@@ -51,12 +51,12 @@ export function extractDescriptions(object: AnyObject) {
/**
* Resolve the first example from an object.
*/
export function resolveFirstExample(object: AnyObject) {
export function resolveFirstExample(object: AnyObject): string | undefined {
if ('examples' in object && typeof object.examples === 'object' && object.examples) {
const keys = Object.keys(object.examples);
const firstKey = keys[0];
if (firstKey && object.examples[firstKey]) {
return object.examples[firstKey];
return formatExample(object.examples[firstKey]);
}
}