diff --git a/src/services/OpenAPIParser.ts b/src/services/OpenAPIParser.ts index 76fbefc9..6b36dc2a 100644 --- a/src/services/OpenAPIParser.ts +++ b/src/services/OpenAPIParser.ts @@ -271,16 +271,13 @@ export class OpenAPIParser { } if (items !== undefined && !isCircular) { - // FIXME: this is invalid here, we need to fix it in separate PR const receiverItems = typeof receiver.items === 'boolean' - ? { items: receiver.items } - : receiver.items - ? (Object.assign({}, receiver.items) as OpenAPISchema) - : {}; + ? {} + : (Object.assign({}, receiver.items) as OpenAPISchema); const subSchemaItems = typeof subSchema.items === 'boolean' - ? { items: subSchema.items } + ? {} : (Object.assign({}, subSchema.items) as OpenAPISchema); // merge inner properties receiver.items = this.mergeAllOf( diff --git a/src/services/__tests__/fixtures/3.1/prefixItems.json b/src/services/__tests__/fixtures/3.1/prefixItems.json index cd527297..9ad145e5 100644 --- a/src/services/__tests__/fixtures/3.1/prefixItems.json +++ b/src/services/__tests__/fixtures/3.1/prefixItems.json @@ -140,6 +140,14 @@ "$ref": "#/components/schemas/Tag" } }, + "Case7": { + "type": "object", + "properties": { + "array_field": { + "$ref": "#/components/schemas/AnyArray" + } + } + }, "Cat": { "type": "object", "properties": { @@ -178,6 +186,10 @@ "type": "integer", "format": "int64", "readOnly": true + }, + "AnyArray": { + "type": "array", + "items": true } } } diff --git a/src/services/__tests__/fixtures/arrayItems.json b/src/services/__tests__/fixtures/arrayItems.json index 51da75ea..c0cb7dce 100644 --- a/src/services/__tests__/fixtures/arrayItems.json +++ b/src/services/__tests__/fixtures/arrayItems.json @@ -140,6 +140,14 @@ "$ref": "#/components/schemas/Tag" } }, + "Case7": { + "type": "object", + "properties": { + "array_field": { + "$ref": "#/components/schemas/AnyArray" + } + } + }, "Cat": { "type": "object", "properties": { @@ -178,6 +186,10 @@ "type": "integer", "format": "int64", "readOnly": true + }, + "AnyArray": { + "type": "array", + "items": true } } } diff --git a/src/services/__tests__/models/Schema.test.ts b/src/services/__tests__/models/Schema.test.ts index 9ad5feff..cf3ddaa1 100644 --- a/src/services/__tests__/models/Schema.test.ts +++ b/src/services/__tests__/models/Schema.test.ts @@ -242,6 +242,21 @@ describe('Models', () => { expect(schema.minItems).toBe(1); }, ); + + test.each(eachArray)( + 'schemaDefinition should resolve items with boolean type', + specFixture => { + const spec = require(specFixture); + const parser = new OpenAPIParser(spec, undefined, opts); + const schema = new SchemaModel(parser, spec.components.schemas.Case7, '', opts); + expect(schema.fields?.[0].schema?.type).toBe('array'); + expect(schema.fields?.[0].schema?.typePrefix).toBe('Array of '); + expect(schema.fields?.[0].schema.items?.displayType).toBe('any'); + expect(schema?.fields).toHaveLength(1); + expect(schema.fields?.[0].schema.pointer).toEqual('#/components/schemas/AnyArray'); + expect(schema.fields?.[0].schema.isPrimitive).toBe(true); + }, + ); }); test('should get correct fields data if it includes allOf', () => { diff --git a/src/services/models/Schema.ts b/src/services/models/Schema.ts index 3b8dcf2d..98bcbd0e 100644 --- a/src/services/models/Schema.ts +++ b/src/services/models/Schema.ts @@ -195,7 +195,7 @@ export class SchemaModel { } else if (this.hasType('array')) { if (isArray(schema.items) || isArray(schema.prefixItems)) { this.fields = buildFields(parser, schema, this.pointer, this.options, this.refsStack); - } else if (isObject(schema.items)) { + } else if (schema.items) { this.items = new SchemaModel( parser, schema.items as OpenAPISchema,