fix: nested patternProperties (#2073)

This commit is contained in:
Alex Varchuk 2022-07-08 11:34:49 +03:00 committed by GitHub
parent 4fc6aa0859
commit 9920991080
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 6 deletions

View File

@ -25,6 +25,26 @@
}
}
}
},
"properties": {
"nestedObjectProp": {
"type": "object",
"patternProperties": {
".*": {
"type": "integer"
}
}
},
"nestedArrayProp": {
"type": "array",
"items": {
"patternProperties": {
".*": {
"type": "string"
}
}
}
}
}
}
}

View File

@ -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', () => {

View File

@ -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)) {