Skip to content

Commit 658eb4d

Browse files
authored
extra check for undefined in schema.items (GitbookIO#250)
1 parent 3725239 commit 658eb4d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/react-openapi/src/OpenAPISchema.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ function getSchemaProperties(schema: OpenAPIV3.SchemaObject): null | OpenAPISche
233233
}, [] as OpenAPISchemaPropertyEntry[]);
234234
}
235235

236-
if (schema.type === 'array') {
236+
// check array AND schema.items as this is sometimes null despite what the type indicates
237+
if (schema.type === 'array' && !!schema.items) {
237238
const items = noReference(schema.items);
238239
const itemProperties = getSchemaProperties(items);
239240
if (itemProperties) {
@@ -352,7 +353,8 @@ function getSchemaTitle(
352353

353354
if (schema.enum) {
354355
type = 'enum';
355-
} else if (schema.type === 'array') {
356+
// check array AND schema.items as this is sometimes null despite what the type indicates
357+
} else if (schema.type === 'array' && !!schema.items) {
356358
type = `array of ${getSchemaTitle(noReference(schema.items))}`;
357359
} else if (schema.type || schema.properties) {
358360
type = schema.type ?? 'object';

0 commit comments

Comments
 (0)