mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 00:26:34 +03:00
fix: recursion for boolean items (#2097)
This commit is contained in:
parent
2384c5afe9
commit
a5804db1ce
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user