mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 10:03:31 +00:00
Fix OpenAPI example (#2944)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix OpenAPI example display error
|
||||||
@@ -217,7 +217,7 @@ function OpenAPISchemaPresentation(props: { property: OpenAPISchemaPropertyEntry
|
|||||||
propertyName={propertyName}
|
propertyName={propertyName}
|
||||||
required={required}
|
required={required}
|
||||||
/>
|
/>
|
||||||
{schema['x-deprecated-sunset'] ? (
|
{typeof schema['x-deprecated-sunset'] === 'string' ? (
|
||||||
<div className="openapi-deprecated-sunset openapi-schema-description openapi-markdown">
|
<div className="openapi-deprecated-sunset openapi-schema-description openapi-markdown">
|
||||||
Sunset date:{' '}
|
Sunset date:{' '}
|
||||||
<span className="openapi-deprecated-sunset-date">
|
<span className="openapi-deprecated-sunset-date">
|
||||||
@@ -228,7 +228,7 @@ function OpenAPISchemaPresentation(props: { property: OpenAPISchemaPropertyEntry
|
|||||||
{description ? (
|
{description ? (
|
||||||
<Markdown source={description} className="openapi-schema-description" />
|
<Markdown source={description} className="openapi-schema-description" />
|
||||||
) : null}
|
) : null}
|
||||||
{example ? (
|
{typeof example === 'string' ? (
|
||||||
<div className="openapi-schema-example">
|
<div className="openapi-schema-example">
|
||||||
Example: <code>{example}</code>
|
Example: <code>{example}</code>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -51,12 +51,12 @@ export function extractDescriptions(object: AnyObject) {
|
|||||||
/**
|
/**
|
||||||
* Resolve the first example from an object.
|
* 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) {
|
if ('examples' in object && typeof object.examples === 'object' && object.examples) {
|
||||||
const keys = Object.keys(object.examples);
|
const keys = Object.keys(object.examples);
|
||||||
const firstKey = keys[0];
|
const firstKey = keys[0];
|
||||||
if (firstKey && object.examples[firstKey]) {
|
if (firstKey && object.examples[firstKey]) {
|
||||||
return object.examples[firstKey];
|
return formatExample(object.examples[firstKey]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user