mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-12 05:48:57 +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}
|
||||
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>
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user