mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-04 04:10:19 +03:00
fix: patternProperties in properties and items
This commit is contained in:
parent
10eeb5ceac
commit
9b9215a5ff
|
@ -25,6 +25,26 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"nestedObjectProp": {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
".*": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nestedArrayProp": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"patternProperties": {
|
||||
".*": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
|
@ -418,7 +418,7 @@ function buildFields(
|
|||
options: RedocNormalizedOptions,
|
||||
): FieldModel[] {
|
||||
const props = schema.properties || schema.prefixItems || schema.items || {};
|
||||
let patternProps = schema.patternProperties || {};
|
||||
const patternProps = schema.patternProperties || {};
|
||||
const additionalProps = schema.additionalProperties || schema.unevaluatedProperties;
|
||||
const itemsProps = schema.prefixItems ? schema.items : schema.additionalItems;
|
||||
const defaults = schema.default;
|
||||
|
@ -432,10 +432,6 @@ function buildFields(
|
|||
field = {};
|
||||
}
|
||||
|
||||
if (field.patternProperties) {
|
||||
patternProps = { ...patternProps, ...field.patternProperties };
|
||||
}
|
||||
|
||||
const required =
|
||||
schema.required === undefined ? false : schema.required.indexOf(fieldName) > -1;
|
||||
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user