diff --git a/.changeset/three-dancers-reflect.md b/.changeset/three-dancers-reflect.md new file mode 100644 index 000000000..f6ffc8a01 --- /dev/null +++ b/.changeset/three-dancers-reflect.md @@ -0,0 +1,5 @@ +--- +'@gitbook/react-openapi': patch +--- + +Update resolveDescription and add minItems/maxItems diff --git a/packages/react-openapi/src/OpenAPISchemaName.tsx b/packages/react-openapi/src/OpenAPISchemaName.tsx index ee3e64f3d..81443644c 100644 --- a/packages/react-openapi/src/OpenAPISchemaName.tsx +++ b/packages/react-openapi/src/OpenAPISchemaName.tsx @@ -40,12 +40,12 @@ export function OpenAPISchemaName(props: OpenAPISchemaNameProps) { function getAdditionalItems(schema: OpenAPIV3.SchemaObject): string { let additionalItems = ''; - if (schema.minimum || schema.minLength) { - additionalItems += ` · min: ${schema.minimum || schema.minLength}`; + if (schema.minimum || schema.minLength || schema.minItems) { + additionalItems += ` · min: ${schema.minimum || schema.minLength || schema.minItems}`; } - if (schema.maximum || schema.maxLength) { - additionalItems += ` · max: ${schema.maximum || schema.maxLength}`; + if (schema.maximum || schema.maxLength || schema.maxItems) { + additionalItems += ` · max: ${schema.maximum || schema.maxLength || schema.maxItems}`; } // If the schema has a default value, we display it diff --git a/packages/react-openapi/src/utils.ts b/packages/react-openapi/src/utils.ts index 2a6ce7b84..0b53baf1d 100644 --- a/packages/react-openapi/src/utils.ts +++ b/packages/react-openapi/src/utils.ts @@ -22,17 +22,22 @@ function hasDescription(object: AnyObject) { * Resolve the description of an object. */ export function resolveDescription(object: OpenAPIV3.SchemaObject | AnyObject) { - // If the object has items and has a description, we resolve the description from items + // Resolve description from the object first + if (hasDescription(object)) { + return 'x-gitbook-description-html' in object && + typeof object['x-gitbook-description-html'] === 'string' + ? object['x-gitbook-description-html'].trim() + : typeof object.description === 'string' + ? object.description.trim() + : undefined; + } + + // If the object has no description, try to resolve it from the items if ('items' in object && typeof object.items === 'object' && hasDescription(object.items)) { return resolveDescription(object.items); } - return 'x-gitbook-description-html' in object && - typeof object['x-gitbook-description-html'] === 'string' - ? object['x-gitbook-description-html'].trim() - : typeof object.description === 'string' - ? object.description.trim() - : undefined; + return undefined; } /**