Skip to content

Commit 7419ee7

Browse files
authored
Show additional fields in OpenAPI block (#2851)
1 parent aa6be38 commit 7419ee7

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

.changeset/shiny-adults-suffer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/react-openapi': patch
3+
---
4+
5+
Show additional fields in OpenAPI block

packages/react-openapi/src/OpenAPISchema.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ export function getSchemaTitle(
397397
let type = 'any';
398398

399399
if (schema.enum) {
400-
type = 'enum';
400+
type = `${schema.type} · enum`;
401401
// check array AND schema.items as this is sometimes null despite what the type indicates
402402
} else if (schema.type === 'array' && !!schema.items) {
403403
type = `${getSchemaTitle(schema.items)}[]`;
@@ -407,7 +407,7 @@ export function getSchemaTitle(
407407
type = schema.type ?? 'object';
408408

409409
if (schema.format) {
410-
type += ` ${schema.format}`;
410+
type += ` · ${schema.format}`;
411411
}
412412
} else if ('anyOf' in schema) {
413413
type = 'any of';
@@ -419,8 +419,20 @@ export function getSchemaTitle(
419419
type = 'not';
420420
}
421421

422+
if (schema.minimum || schema.minLength) {
423+
type += ` · min: ${schema.minimum || schema.minLength}`;
424+
}
425+
426+
if (schema.maximum || schema.maxLength) {
427+
type += ` · max: ${schema.maximum || schema.maxLength}`;
428+
}
429+
430+
if (schema.default) {
431+
type += ` · default: ${schema.default}`;
432+
}
433+
422434
if (schema.nullable) {
423-
type = `nullable ${type}`;
435+
type = `${type} | nullable`;
424436
}
425437

426438
return type;

0 commit comments

Comments
 (0)