#1892 fixed multiple definition loops
This commit is contained in:
30
dist/swagger-ui.js
vendored
30
dist/swagger-ui.js
vendored
@@ -27127,7 +27127,7 @@ SwaggerUi.partials.signature = (function () {
|
||||
}
|
||||
|
||||
function getInfiniteLoopMessage (name) {
|
||||
return '<!-- Infinite loop to model ' + name + ' -->';
|
||||
return '<!-- Infinite loop $ref:' + name + ' -->';
|
||||
}
|
||||
|
||||
function getErrorMessage () {
|
||||
@@ -27135,7 +27135,10 @@ SwaggerUi.partials.signature = (function () {
|
||||
}
|
||||
|
||||
function createSchemaXML (name, definition, models, config) {
|
||||
var $ref = definition.$ref;
|
||||
var $ref = _.isObject(definition) ? definition.$ref : null;
|
||||
var output, index;
|
||||
config = config || {};
|
||||
config.modelsToIgnore = config.modelsToIgnore || [];
|
||||
var descriptor = _.isString($ref) ? getDescriptorByRef($ref, models, config)
|
||||
: getDescriptor(name, definition, models, config);
|
||||
|
||||
@@ -27145,14 +27148,23 @@ SwaggerUi.partials.signature = (function () {
|
||||
|
||||
switch (descriptor.type) {
|
||||
case 'array':
|
||||
return createArrayXML(descriptor);
|
||||
output = createArrayXML(descriptor); break;
|
||||
case 'object':
|
||||
return createObjectXML(descriptor);
|
||||
output = createObjectXML(descriptor); break;
|
||||
case 'loop':
|
||||
return getInfiniteLoopMessage(descriptor.name);
|
||||
output = getInfiniteLoopMessage(descriptor.name); break;
|
||||
default:
|
||||
return createPrimitiveXML(descriptor);
|
||||
output = createPrimitiveXML(descriptor);
|
||||
}
|
||||
|
||||
if ($ref) {
|
||||
index = config.modelsToIgnore.indexOf($ref);
|
||||
if (index > -1) {
|
||||
config.modelsToIgnore.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
function Descriptor (name, type, definition, models, config) {
|
||||
@@ -27174,12 +27186,10 @@ SwaggerUi.partials.signature = (function () {
|
||||
var name = model.name || modelType;
|
||||
var type = model.type || 'object';
|
||||
|
||||
config = config || {};
|
||||
config.modelsToIgnore = config.modelsToIgnore || [];
|
||||
if (config.modelsToIgnore.indexOf(name) > -1) {
|
||||
if (config.modelsToIgnore.indexOf($ref) > -1) {
|
||||
type = 'loop';
|
||||
} else {
|
||||
config.modelsToIgnore.push(modelType);
|
||||
config.modelsToIgnore.push($ref);
|
||||
}
|
||||
|
||||
if (!model.definition) {
|
||||
|
||||
20
dist/swagger-ui.min.js
vendored
20
dist/swagger-ui.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -824,7 +824,7 @@ SwaggerUi.partials.signature = (function () {
|
||||
}
|
||||
|
||||
function getInfiniteLoopMessage (name) {
|
||||
return '<!-- Infinite loop to model ' + name + ' -->';
|
||||
return '<!-- Infinite loop $ref:' + name + ' -->';
|
||||
}
|
||||
|
||||
function getErrorMessage () {
|
||||
@@ -832,7 +832,10 @@ SwaggerUi.partials.signature = (function () {
|
||||
}
|
||||
|
||||
function createSchemaXML (name, definition, models, config) {
|
||||
var $ref = definition.$ref;
|
||||
var $ref = _.isObject(definition) ? definition.$ref : null;
|
||||
var output, index;
|
||||
config = config || {};
|
||||
config.modelsToIgnore = config.modelsToIgnore || [];
|
||||
var descriptor = _.isString($ref) ? getDescriptorByRef($ref, models, config)
|
||||
: getDescriptor(name, definition, models, config);
|
||||
|
||||
@@ -842,14 +845,23 @@ SwaggerUi.partials.signature = (function () {
|
||||
|
||||
switch (descriptor.type) {
|
||||
case 'array':
|
||||
return createArrayXML(descriptor);
|
||||
output = createArrayXML(descriptor); break;
|
||||
case 'object':
|
||||
return createObjectXML(descriptor);
|
||||
output = createObjectXML(descriptor); break;
|
||||
case 'loop':
|
||||
return getInfiniteLoopMessage(descriptor.name);
|
||||
output = getInfiniteLoopMessage(descriptor.name); break;
|
||||
default:
|
||||
return createPrimitiveXML(descriptor);
|
||||
output = createPrimitiveXML(descriptor);
|
||||
}
|
||||
|
||||
if ($ref) {
|
||||
index = config.modelsToIgnore.indexOf($ref);
|
||||
if (index > -1) {
|
||||
config.modelsToIgnore.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
function Descriptor (name, type, definition, models, config) {
|
||||
@@ -871,12 +883,10 @@ SwaggerUi.partials.signature = (function () {
|
||||
var name = model.name || modelType;
|
||||
var type = model.type || 'object';
|
||||
|
||||
config = config || {};
|
||||
config.modelsToIgnore = config.modelsToIgnore || [];
|
||||
if (config.modelsToIgnore.indexOf(name) > -1) {
|
||||
if (config.modelsToIgnore.indexOf($ref) > -1) {
|
||||
type = 'loop';
|
||||
} else {
|
||||
config.modelsToIgnore.push(modelType);
|
||||
config.modelsToIgnore.push($ref);
|
||||
}
|
||||
|
||||
if (!model.definition) {
|
||||
|
||||
@@ -502,7 +502,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
||||
}
|
||||
};
|
||||
|
||||
expect(sut.createSchemaXML(name, definition, models, true)).to.equal(expected);
|
||||
expect(sut.createSchemaXML(name, definition, models, {isParam: true})).to.equal(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -554,7 +554,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
||||
'<id>1</id>' +
|
||||
'<Loop2>' +
|
||||
'<id>1</id>' +
|
||||
'<!-- Infinite loop to model Loop1 -->' +
|
||||
'<!-- Infinite loop $ref:Loop1 -->' +
|
||||
'</Loop2>' +
|
||||
'</Loop1>';
|
||||
var schema = {
|
||||
@@ -570,7 +570,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
||||
'<id>1</id>' +
|
||||
'<Loop2>' +
|
||||
'<id>1</id>' +
|
||||
'<!-- Infinite loop to model Loop1 -->' +
|
||||
'<!-- Infinite loop $ref:Loop1 -->' +
|
||||
'</Loop2>' +
|
||||
'</Loop1>' +
|
||||
'</Loop3>';
|
||||
@@ -580,6 +580,74 @@ describe('SwaggerUi.partials.signature tests', function () {
|
||||
|
||||
expect(sut.createSchemaXML('', schema, models)).to.equal(expected);
|
||||
});
|
||||
|
||||
it('infinite loop Loop1 => Loop2, Loop2 => Loop1 with 2 different loops on one level', function () {
|
||||
var expected = '<Pet><Loop1>' +
|
||||
'<id>1</id>' +
|
||||
'<Loop2>' +
|
||||
'<id>1</id>' +
|
||||
'<!-- Infinite loop $ref:Loop1 -->' +
|
||||
'</Loop2>' +
|
||||
'</Loop1>' +
|
||||
'<Loop2>' +
|
||||
'<id>1</id>' +
|
||||
'<Loop1>' +
|
||||
'<id>1</id>' +
|
||||
'<!-- Infinite loop $ref:Loop2 -->' +
|
||||
'</Loop1>' +
|
||||
'</Loop2>' +
|
||||
'</Pet>';
|
||||
var schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
item1: {
|
||||
$ref: '#/definitions/Loop1'
|
||||
},
|
||||
item2: {
|
||||
$ref: '#/definitions/Loop2'
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: 'Pet'
|
||||
}
|
||||
};
|
||||
|
||||
expect(sut.createSchemaXML('', schema, models)).to.equal(expected);
|
||||
});
|
||||
|
||||
it('infinite loop Loop1 => Loop2, Loop2 => Loop1 with 2 different loops on one level', function () {
|
||||
var expected = '<Pet><Loop1>' +
|
||||
'<id>1</id>' +
|
||||
'<Loop2>' +
|
||||
'<id>1</id>' +
|
||||
'<!-- Infinite loop $ref:Loop1 -->' +
|
||||
'</Loop2>' +
|
||||
'</Loop1>' +
|
||||
'<Loop1>' +
|
||||
'<id>1</id>' +
|
||||
'<Loop2>' +
|
||||
'<id>1</id>' +
|
||||
'<!-- Infinite loop $ref:Loop1 -->' +
|
||||
'</Loop2>' +
|
||||
'</Loop1>' +
|
||||
'</Pet>';
|
||||
var schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
item1: {
|
||||
$ref: '#/definitions/Loop1'
|
||||
},
|
||||
item2: {
|
||||
$ref: '#/definitions/Loop1'
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: 'Pet'
|
||||
}
|
||||
};
|
||||
|
||||
expect(sut.createSchemaXML('', schema, models)).to.equal(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user