Add test for new allOf circular detection case

This commit is contained in:
craigmc08 2019-07-16 16:09:54 -04:00
parent 561f146803
commit b9c93c7061
2 changed files with 59 additions and 0 deletions

View File

@ -12,5 +12,13 @@ describe('Models', () => {
parser = new OpenAPIParser(spec, undefined, opts);
expect(parser.mergeAllOf(spec.components.schemas.test)).toMatchSnapshot();
});
test('should not mark as circular when multiple schemas in allOf use the same ref', () => {
const spec = require('./fixtures/allOfCircular.json');
parser = new OpenAPIParser(spec, undefined, opts);
expect(
parser.mergeAllOf(spec.components.schemas.test).properties.object['x-circular-ref'],
).toEqual(undefined);
});
});
});

View File

@ -0,0 +1,51 @@
{
"openapi": "3.0.0",
"info": {
"version": "1.0",
"title": "Foo"
},
"components": {
"schemas": {
"BaseObj": {
"type": "object",
"properties": {
"test": {
"type": "string"
}
}
},
"ExtendedObj": {
"allOf": [
{
"$ref": "#/components/schemas/BaseObj"
},
{
"description": "Extended"
}
]
},
"Base": {
"type": "object",
"properties": {
"object": {
"$ref": "#/components/schemas/BaseObj"
}
}
},
"test": {
"allOf": [
{
"$ref": "#/components/schemas/Base"
},
{
"properties": {
"object": {
"$ref": "#/components/schemas/ExtendedObj"
}
}
}
]
}
}
}
}