Update resolveDescription and add minItems/maxItems (#3000)

This commit is contained in:
Nolann B.
2025-03-19 17:21:35 +01:00
committed by GitHub
parent 24b7808d9a
commit a84b06bb19
3 changed files with 21 additions and 11 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@gitbook/react-openapi': patch
---
Update resolveDescription and add minItems/maxItems
@@ -40,12 +40,12 @@ export function OpenAPISchemaName(props: OpenAPISchemaNameProps) {
function getAdditionalItems(schema: OpenAPIV3.SchemaObject): string { function getAdditionalItems(schema: OpenAPIV3.SchemaObject): string {
let additionalItems = ''; let additionalItems = '';
if (schema.minimum || schema.minLength) { if (schema.minimum || schema.minLength || schema.minItems) {
additionalItems += ` · min: ${schema.minimum || schema.minLength}`; additionalItems += ` · min: ${schema.minimum || schema.minLength || schema.minItems}`;
} }
if (schema.maximum || schema.maxLength) { if (schema.maximum || schema.maxLength || schema.maxItems) {
additionalItems += ` · max: ${schema.maximum || schema.maxLength}`; additionalItems += ` · max: ${schema.maximum || schema.maxLength || schema.maxItems}`;
} }
// If the schema has a default value, we display it // If the schema has a default value, we display it
+12 -7
View File
@@ -22,17 +22,22 @@ function hasDescription(object: AnyObject) {
* Resolve the description of an object. * Resolve the description of an object.
*/ */
export function resolveDescription(object: OpenAPIV3.SchemaObject | AnyObject) { 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)) { if ('items' in object && typeof object.items === 'object' && hasDescription(object.items)) {
return resolveDescription(object.items); return resolveDescription(object.items);
} }
return 'x-gitbook-description-html' in object && return undefined;
typeof object['x-gitbook-description-html'] === 'string'
? object['x-gitbook-description-html'].trim()
: typeof object.description === 'string'
? object.description.trim()
: undefined;
} }
/** /**