Skip to content

Commit a84b06b

Browse files
authored
Update resolveDescription and add minItems/maxItems (#3000)
1 parent 24b7808 commit a84b06b

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

.changeset/three-dancers-reflect.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/react-openapi': patch
3+
---
4+
5+
Update resolveDescription and add minItems/maxItems

packages/react-openapi/src/OpenAPISchemaName.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ export function OpenAPISchemaName(props: OpenAPISchemaNameProps) {
4040
function getAdditionalItems(schema: OpenAPIV3.SchemaObject): string {
4141
let additionalItems = '';
4242

43-
if (schema.minimum || schema.minLength) {
44-
additionalItems += ` · min: ${schema.minimum || schema.minLength}`;
43+
if (schema.minimum || schema.minLength || schema.minItems) {
44+
additionalItems += ` · min: ${schema.minimum || schema.minLength || schema.minItems}`;
4545
}
4646

47-
if (schema.maximum || schema.maxLength) {
48-
additionalItems += ` · max: ${schema.maximum || schema.maxLength}`;
47+
if (schema.maximum || schema.maxLength || schema.maxItems) {
48+
additionalItems += ` · max: ${schema.maximum || schema.maxLength || schema.maxItems}`;
4949
}
5050

5151
// If the schema has a default value, we display it

packages/react-openapi/src/utils.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,22 @@ function hasDescription(object: AnyObject) {
2222
* Resolve the description of an object.
2323
*/
2424
export function resolveDescription(object: OpenAPIV3.SchemaObject | AnyObject) {
25-
// If the object has items and has a description, we resolve the description from items
25+
// Resolve description from the object first
26+
if (hasDescription(object)) {
27+
return 'x-gitbook-description-html' in object &&
28+
typeof object['x-gitbook-description-html'] === 'string'
29+
? object['x-gitbook-description-html'].trim()
30+
: typeof object.description === 'string'
31+
? object.description.trim()
32+
: undefined;
33+
}
34+
35+
// If the object has no description, try to resolve it from the items
2636
if ('items' in object && typeof object.items === 'object' && hasDescription(object.items)) {
2737
return resolveDescription(object.items);
2838
}
2939

30-
return 'x-gitbook-description-html' in object &&
31-
typeof object['x-gitbook-description-html'] === 'string'
32-
? object['x-gitbook-description-html'].trim()
33-
: typeof object.description === 'string'
34-
? object.description.trim()
35-
: undefined;
40+
return undefined;
3641
}
3742

3843
/**

0 commit comments

Comments
 (0)