diff --git a/src/services/__tests__/fixtures/3.1/patternProperties.json b/src/services/__tests__/fixtures/3.1/patternProperties.json index ec686421..39928813 100644 --- a/src/services/__tests__/fixtures/3.1/patternProperties.json +++ b/src/services/__tests__/fixtures/3.1/patternProperties.json @@ -25,6 +25,26 @@ } } } + }, + "properties": { + "nestedObjectProp": { + "type": "object", + "patternProperties": { + ".*": { + "type": "integer" + } + } + }, + "nestedArrayProp": { + "type": "array", + "items": { + "patternProperties": { + ".*": { + "type": "string" + } + } + } + } } } } diff --git a/src/services/__tests__/models/Schema.test.ts b/src/services/__tests__/models/Schema.test.ts index 89c44365..8e73879a 100644 --- a/src/services/__tests__/models/Schema.test.ts +++ b/src/services/__tests__/models/Schema.test.ts @@ -107,11 +107,22 @@ describe('Models', () => { const spec = require('../fixtures/3.1/patternProperties.json'); parser = new OpenAPIParser(spec, undefined, opts); const schema = new SchemaModel(parser, spec.components.schemas.Patterns, '', opts); - expect(schema.fields).toHaveLength(2); - expect(schema.fields![0].kind).toEqual('patternProperties'); - expect(schema.fields![0].schema.type).toEqual('string'); - expect(schema.fields![1].kind).toEqual('patternProperties'); - expect(schema.fields![1].schema.type).toEqual('object'); + + expect(schema.fields).toHaveLength(4); + expect(schema.fields![0].kind).toEqual('field'); + expect(schema.fields![0].name).toEqual('nestedObjectProp'); + expect(schema.fields![0].schema.type).toEqual('object'); + expect(schema.fields![0].schema.fields![0].kind).toEqual('patternProperties'); + + expect(schema.fields).toHaveLength(4); + expect(schema.fields![1].kind).toEqual('field'); + expect(schema.fields![1].name).toEqual('nestedArrayProp'); + expect(schema.fields![1].schema.items!.fields![0].kind).toEqual('patternProperties'); + + expect(schema.fields![2].kind).toEqual('patternProperties'); + expect(schema.fields![2].schema.type).toEqual('string'); + expect(schema.fields![3].kind).toEqual('patternProperties'); + expect(schema.fields![3].schema.type).toEqual('object'); }); describe('type array', () => { diff --git a/src/utils/openapi.ts b/src/utils/openapi.ts index 2e47399f..272f04f9 100644 --- a/src/utils/openapi.ts +++ b/src/utils/openapi.ts @@ -136,7 +136,9 @@ export function isPrimitiveType( isPrimitive = schema.properties !== undefined ? Object.keys(schema.properties).length === 0 - : schema.additionalProperties === undefined && schema.unevaluatedProperties === undefined; + : schema.additionalProperties === undefined && + schema.unevaluatedProperties === undefined && + schema.patternProperties === undefined; } if (isArray(schema.items) || isArray(schema.prefixItems)) {