diff --git a/.changeset/shiny-adults-suffer.md b/.changeset/shiny-adults-suffer.md new file mode 100644 index 000000000..5b1cf1950 --- /dev/null +++ b/.changeset/shiny-adults-suffer.md @@ -0,0 +1,5 @@ +--- +'@gitbook/react-openapi': patch +--- + +Show additional fields in OpenAPI block diff --git a/packages/react-openapi/src/OpenAPISchema.tsx b/packages/react-openapi/src/OpenAPISchema.tsx index 130bb7828..bc2693661 100644 --- a/packages/react-openapi/src/OpenAPISchema.tsx +++ b/packages/react-openapi/src/OpenAPISchema.tsx @@ -397,7 +397,7 @@ export function getSchemaTitle( let type = 'any'; if (schema.enum) { - type = 'enum'; + type = `${schema.type} · enum`; // check array AND schema.items as this is sometimes null despite what the type indicates } else if (schema.type === 'array' && !!schema.items) { type = `${getSchemaTitle(schema.items)}[]`; @@ -407,7 +407,7 @@ export function getSchemaTitle( type = schema.type ?? 'object'; if (schema.format) { - type += ` ${schema.format}`; + type += ` · ${schema.format}`; } } else if ('anyOf' in schema) { type = 'any of'; @@ -419,8 +419,20 @@ export function getSchemaTitle( type = 'not'; } + if (schema.minimum || schema.minLength) { + type += ` · min: ${schema.minimum || schema.minLength}`; + } + + if (schema.maximum || schema.maxLength) { + type += ` · max: ${schema.maximum || schema.maxLength}`; + } + + if (schema.default) { + type += ` · default: ${schema.default}`; + } + if (schema.nullable) { - type = `nullable ${type}`; + type = `${type} | nullable`; } return type;