mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-12 05:48:57 +00:00
Update resolveDescription and add minItems/maxItems (#3000)
This commit is contained in:
@@ -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 {
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user