#1892 infinite loop when rendering self-references
This commit is contained in:
2
dist/css/print.css
vendored
2
dist/css/print.css
vendored
@@ -82,7 +82,7 @@
|
|||||||
.swagger-section pre .vhdl .attribute,
|
.swagger-section pre .vhdl .attribute,
|
||||||
.swagger-section pre .clojure .attribute,
|
.swagger-section pre .clojure .attribute,
|
||||||
.swagger-section pre .coffeescript .property {
|
.swagger-section pre .coffeescript .property {
|
||||||
color: #8888ff;
|
color: #88F;
|
||||||
}
|
}
|
||||||
.swagger-section pre .keyword,
|
.swagger-section pre .keyword,
|
||||||
.swagger-section pre .id,
|
.swagger-section pre .id,
|
||||||
|
|||||||
2
dist/css/screen.css
vendored
2
dist/css/screen.css
vendored
@@ -82,7 +82,7 @@
|
|||||||
.swagger-section pre .vhdl .attribute,
|
.swagger-section pre .vhdl .attribute,
|
||||||
.swagger-section pre .clojure .attribute,
|
.swagger-section pre .clojure .attribute,
|
||||||
.swagger-section pre .coffeescript .property {
|
.swagger-section pre .coffeescript .property {
|
||||||
color: #8888ff;
|
color: #88F;
|
||||||
}
|
}
|
||||||
.swagger-section pre .keyword,
|
.swagger-section pre .keyword,
|
||||||
.swagger-section pre .id,
|
.swagger-section pre .id,
|
||||||
|
|||||||
47
dist/swagger-ui.js
vendored
47
dist/swagger-ui.js
vendored
@@ -27015,6 +27015,7 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
|
|
||||||
var createArrayXML = function (descriptor) {
|
var createArrayXML = function (descriptor) {
|
||||||
var name = descriptor.name;
|
var name = descriptor.name;
|
||||||
|
var config = descriptor.config;
|
||||||
var definition = descriptor.definition;
|
var definition = descriptor.definition;
|
||||||
var models = descriptor.models;
|
var models = descriptor.models;
|
||||||
var value;
|
var value;
|
||||||
@@ -27023,7 +27024,7 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
|
|
||||||
if (!items) { return getErrorMessage(); }
|
if (!items) { return getErrorMessage(); }
|
||||||
|
|
||||||
value = createSchemaXML(name, items, models);
|
value = createSchemaXML(name, items, models, config);
|
||||||
|
|
||||||
xml = xml || {};
|
xml = xml || {};
|
||||||
|
|
||||||
@@ -27082,8 +27083,9 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
function createObjectXML (descriptor) {
|
function createObjectXML (descriptor) {
|
||||||
var name = descriptor.name;
|
var name = descriptor.name;
|
||||||
var definition = descriptor.definition;
|
var definition = descriptor.definition;
|
||||||
|
var config = descriptor.config;
|
||||||
var models = descriptor.models;
|
var models = descriptor.models;
|
||||||
var isParam = descriptor.isParam;
|
var isParam = descriptor.config.isParam;
|
||||||
var serializedProperties;
|
var serializedProperties;
|
||||||
var attrs = [];
|
var attrs = [];
|
||||||
var properties = definition.properties;
|
var properties = definition.properties;
|
||||||
@@ -27102,10 +27104,12 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
serializedProperties = _.map(properties, function (prop, key) {
|
serializedProperties = _.map(properties, function (prop, key) {
|
||||||
var xml, result;
|
var xml, result;
|
||||||
|
|
||||||
if (isParam && prop.readOnly) { return ''; }
|
if (isParam && prop.readOnly) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
xml = prop.xml || {};
|
xml = prop.xml || {};
|
||||||
result = createSchemaXML(key, prop, models);
|
result = createSchemaXML(key, prop, models, config);
|
||||||
|
|
||||||
if (xml.attribute) {
|
if (xml.attribute) {
|
||||||
attrs.push(result);
|
attrs.push(result);
|
||||||
@@ -27122,14 +27126,18 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
return wrapTag(name, serializedProperties, attrs);
|
return wrapTag(name, serializedProperties, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getInfiniteLoopMessage (name) {
|
||||||
|
return '<!-- Infinite loop to model ' + name + ' -->';
|
||||||
|
}
|
||||||
|
|
||||||
function getErrorMessage () {
|
function getErrorMessage () {
|
||||||
return '<!-- invalid XML -->';
|
return '<!-- invalid XML -->';
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSchemaXML (name, definition, models, isParam) {
|
function createSchemaXML (name, definition, models, config) {
|
||||||
var $ref = definition.$ref;
|
var $ref = definition.$ref;
|
||||||
var descriptor = _.isString($ref) ? getDescriptorByRef($ref, models)
|
var descriptor = _.isString($ref) ? getDescriptorByRef($ref, models, config)
|
||||||
: getDescriptor(name, definition, models, isParam);
|
: getDescriptor(name, definition, models, config);
|
||||||
|
|
||||||
if (!descriptor) {
|
if (!descriptor) {
|
||||||
return getErrorMessage();
|
return getErrorMessage();
|
||||||
@@ -27140,37 +27148,48 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
return createArrayXML(descriptor);
|
return createArrayXML(descriptor);
|
||||||
case 'object':
|
case 'object':
|
||||||
return createObjectXML(descriptor);
|
return createObjectXML(descriptor);
|
||||||
|
case 'loop':
|
||||||
|
return getInfiniteLoopMessage(descriptor.name);
|
||||||
default:
|
default:
|
||||||
return createPrimitiveXML(descriptor);
|
return createPrimitiveXML(descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Descriptor (name, type, definition, models, isParam) {
|
function Descriptor (name, type, definition, models, config) {
|
||||||
if (arguments.length < 4) {
|
if (arguments.length < 4) {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.config = config || {};
|
||||||
|
this.config.modelsToIgnore = this.config.modelsToIgnore || [];
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.definition = definition;
|
this.definition = definition;
|
||||||
this.models = models;
|
this.models = models;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.isParam = isParam;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDescriptorByRef($ref, models) {
|
function getDescriptorByRef($ref, models, config) {
|
||||||
var modelType = simpleRef($ref);
|
var modelType = simpleRef($ref);
|
||||||
var model = models[modelType] || {};
|
var model = models[modelType] || {};
|
||||||
var name = model.name || modelType;
|
var name = model.name || modelType;
|
||||||
var type = model.type || 'object';
|
var type = model.type || 'object';
|
||||||
|
|
||||||
|
config = config || {};
|
||||||
|
config.modelsToIgnore = config.modelsToIgnore || [];
|
||||||
|
if (config.modelsToIgnore.indexOf(name) > -1) {
|
||||||
|
type = 'loop';
|
||||||
|
} else {
|
||||||
|
config.modelsToIgnore.push(modelType);
|
||||||
|
}
|
||||||
|
|
||||||
if (!model.definition) {
|
if (!model.definition) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Descriptor (name, type, model.definition, models);
|
return new Descriptor(name, type, model.definition, models, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDescriptor (name, definition, models, isParam){
|
function getDescriptor (name, definition, models, config){
|
||||||
var type = definition.type || 'object';
|
var type = definition.type || 'object';
|
||||||
var xml = definition.xml || {};
|
var xml = definition.xml || {};
|
||||||
|
|
||||||
@@ -27180,13 +27199,13 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
|
|
||||||
name = getName(name, xml);
|
name = getName(name, xml);
|
||||||
|
|
||||||
return new Descriptor(name, type, definition, models,isParam);
|
return new Descriptor(name, type, definition, models, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createXMLSample (definition, models, isParam) {
|
function createXMLSample (definition, models, isParam) {
|
||||||
var prolog = '<?xml version="1.0"?>';
|
var prolog = '<?xml version="1.0"?>';
|
||||||
|
|
||||||
return formatXml(prolog + createSchemaXML('', definition, models, isParam));
|
return formatXml(prolog + createSchemaXML('', definition, models, { isParam: isParam } ));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
6
dist/swagger-ui.min.js
vendored
6
dist/swagger-ui.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -82,7 +82,7 @@
|
|||||||
.swagger-section pre .vhdl .attribute,
|
.swagger-section pre .vhdl .attribute,
|
||||||
.swagger-section pre .clojure .attribute,
|
.swagger-section pre .clojure .attribute,
|
||||||
.swagger-section pre .coffeescript .property {
|
.swagger-section pre .coffeescript .property {
|
||||||
color: #8888ff;
|
color: #88F;
|
||||||
}
|
}
|
||||||
.swagger-section pre .keyword,
|
.swagger-section pre .keyword,
|
||||||
.swagger-section pre .id,
|
.swagger-section pre .id,
|
||||||
|
|||||||
@@ -82,7 +82,7 @@
|
|||||||
.swagger-section pre .vhdl .attribute,
|
.swagger-section pre .vhdl .attribute,
|
||||||
.swagger-section pre .clojure .attribute,
|
.swagger-section pre .clojure .attribute,
|
||||||
.swagger-section pre .coffeescript .property {
|
.swagger-section pre .coffeescript .property {
|
||||||
color: #8888ff;
|
color: #88F;
|
||||||
}
|
}
|
||||||
.swagger-section pre .keyword,
|
.swagger-section pre .keyword,
|
||||||
.swagger-section pre .id,
|
.swagger-section pre .id,
|
||||||
|
|||||||
@@ -712,6 +712,7 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
|
|
||||||
var createArrayXML = function (descriptor) {
|
var createArrayXML = function (descriptor) {
|
||||||
var name = descriptor.name;
|
var name = descriptor.name;
|
||||||
|
var config = descriptor.config;
|
||||||
var definition = descriptor.definition;
|
var definition = descriptor.definition;
|
||||||
var models = descriptor.models;
|
var models = descriptor.models;
|
||||||
var value;
|
var value;
|
||||||
@@ -720,7 +721,7 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
|
|
||||||
if (!items) { return getErrorMessage(); }
|
if (!items) { return getErrorMessage(); }
|
||||||
|
|
||||||
value = createSchemaXML(name, items, models);
|
value = createSchemaXML(name, items, models, config);
|
||||||
|
|
||||||
xml = xml || {};
|
xml = xml || {};
|
||||||
|
|
||||||
@@ -779,8 +780,9 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
function createObjectXML (descriptor) {
|
function createObjectXML (descriptor) {
|
||||||
var name = descriptor.name;
|
var name = descriptor.name;
|
||||||
var definition = descriptor.definition;
|
var definition = descriptor.definition;
|
||||||
|
var config = descriptor.config;
|
||||||
var models = descriptor.models;
|
var models = descriptor.models;
|
||||||
var isParam = descriptor.isParam;
|
var isParam = descriptor.config.isParam;
|
||||||
var serializedProperties;
|
var serializedProperties;
|
||||||
var attrs = [];
|
var attrs = [];
|
||||||
var properties = definition.properties;
|
var properties = definition.properties;
|
||||||
@@ -799,10 +801,12 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
serializedProperties = _.map(properties, function (prop, key) {
|
serializedProperties = _.map(properties, function (prop, key) {
|
||||||
var xml, result;
|
var xml, result;
|
||||||
|
|
||||||
if (isParam && prop.readOnly) { return ''; }
|
if (isParam && prop.readOnly) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
xml = prop.xml || {};
|
xml = prop.xml || {};
|
||||||
result = createSchemaXML(key, prop, models);
|
result = createSchemaXML(key, prop, models, config);
|
||||||
|
|
||||||
if (xml.attribute) {
|
if (xml.attribute) {
|
||||||
attrs.push(result);
|
attrs.push(result);
|
||||||
@@ -819,14 +823,18 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
return wrapTag(name, serializedProperties, attrs);
|
return wrapTag(name, serializedProperties, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getInfiniteLoopMessage (name) {
|
||||||
|
return '<!-- Infinite loop to model ' + name + ' -->';
|
||||||
|
}
|
||||||
|
|
||||||
function getErrorMessage () {
|
function getErrorMessage () {
|
||||||
return '<!-- invalid XML -->';
|
return '<!-- invalid XML -->';
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSchemaXML (name, definition, models, isParam) {
|
function createSchemaXML (name, definition, models, config) {
|
||||||
var $ref = definition.$ref;
|
var $ref = definition.$ref;
|
||||||
var descriptor = _.isString($ref) ? getDescriptorByRef($ref, models)
|
var descriptor = _.isString($ref) ? getDescriptorByRef($ref, models, config)
|
||||||
: getDescriptor(name, definition, models, isParam);
|
: getDescriptor(name, definition, models, config);
|
||||||
|
|
||||||
if (!descriptor) {
|
if (!descriptor) {
|
||||||
return getErrorMessage();
|
return getErrorMessage();
|
||||||
@@ -837,37 +845,48 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
return createArrayXML(descriptor);
|
return createArrayXML(descriptor);
|
||||||
case 'object':
|
case 'object':
|
||||||
return createObjectXML(descriptor);
|
return createObjectXML(descriptor);
|
||||||
|
case 'loop':
|
||||||
|
return getInfiniteLoopMessage(descriptor.name);
|
||||||
default:
|
default:
|
||||||
return createPrimitiveXML(descriptor);
|
return createPrimitiveXML(descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Descriptor (name, type, definition, models, isParam) {
|
function Descriptor (name, type, definition, models, config) {
|
||||||
if (arguments.length < 4) {
|
if (arguments.length < 4) {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.config = config || {};
|
||||||
|
this.config.modelsToIgnore = this.config.modelsToIgnore || [];
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.definition = definition;
|
this.definition = definition;
|
||||||
this.models = models;
|
this.models = models;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.isParam = isParam;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDescriptorByRef($ref, models) {
|
function getDescriptorByRef($ref, models, config) {
|
||||||
var modelType = simpleRef($ref);
|
var modelType = simpleRef($ref);
|
||||||
var model = models[modelType] || {};
|
var model = models[modelType] || {};
|
||||||
var name = model.name || modelType;
|
var name = model.name || modelType;
|
||||||
var type = model.type || 'object';
|
var type = model.type || 'object';
|
||||||
|
|
||||||
|
config = config || {};
|
||||||
|
config.modelsToIgnore = config.modelsToIgnore || [];
|
||||||
|
if (config.modelsToIgnore.indexOf(name) > -1) {
|
||||||
|
type = 'loop';
|
||||||
|
} else {
|
||||||
|
config.modelsToIgnore.push(modelType);
|
||||||
|
}
|
||||||
|
|
||||||
if (!model.definition) {
|
if (!model.definition) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Descriptor (name, type, model.definition, models);
|
return new Descriptor(name, type, model.definition, models, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDescriptor (name, definition, models, isParam){
|
function getDescriptor (name, definition, models, config){
|
||||||
var type = definition.type || 'object';
|
var type = definition.type || 'object';
|
||||||
var xml = definition.xml || {};
|
var xml = definition.xml || {};
|
||||||
|
|
||||||
@@ -877,13 +896,13 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
|
|
||||||
name = getName(name, xml);
|
name = getName(name, xml);
|
||||||
|
|
||||||
return new Descriptor(name, type, definition, models,isParam);
|
return new Descriptor(name, type, definition, models, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createXMLSample (definition, models, isParam) {
|
function createXMLSample (definition, models, isParam) {
|
||||||
var prolog = '<?xml version="1.0"?>';
|
var prolog = '<?xml version="1.0"?>';
|
||||||
|
|
||||||
return formatXml(prolog + createSchemaXML('', definition, models, isParam));
|
return formatXml(prolog + createSchemaXML('', definition, models, { isParam: isParam } ));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -61,6 +61,44 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
'xml': { 'name': 'Tag' }
|
'xml': { 'name': 'Tag' }
|
||||||
},
|
},
|
||||||
'name': 'Tag'
|
'name': 'Tag'
|
||||||
|
},
|
||||||
|
'Loop1': {
|
||||||
|
'definition': {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'id': { 'type': 'integer'},
|
||||||
|
'loop2': {
|
||||||
|
'$ref': '#/definitions/Loop2'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'xml': { 'name': 'Loop1' }
|
||||||
|
},
|
||||||
|
'name': 'Loop1'
|
||||||
|
},
|
||||||
|
'Loop2': {
|
||||||
|
'definition': {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'id': { 'type': 'integer'},
|
||||||
|
'loop1': {
|
||||||
|
'$ref': '#/definitions/Loop1'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'xml': { 'name': 'Loop2' }
|
||||||
|
},
|
||||||
|
'name': 'Loop2'
|
||||||
|
},
|
||||||
|
'Loop3': {
|
||||||
|
'definition': {
|
||||||
|
'type': 'object',
|
||||||
|
'properties' : {
|
||||||
|
'loop1': {
|
||||||
|
'$ref': '#/definitions/Loop1'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'xml': { 'name': 'Loop3' }
|
||||||
|
},
|
||||||
|
'name': 'Loop3'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -438,7 +476,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);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns object with passed parameter as attribute', function () {
|
it('returns object with passed parameter as attribute', function () {
|
||||||
@@ -510,6 +548,38 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
|
|
||||||
expect(sut.createSchemaXML('', schema, models)).to.equal(expected);
|
expect(sut.createSchemaXML('', schema, models)).to.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('infinite loop Loop1 => Loop2, Loop2 => Loop1', function () {
|
||||||
|
var expected = '<Loop1>' +
|
||||||
|
'<id>1</id>' +
|
||||||
|
'<Loop2>' +
|
||||||
|
'<id>1</id>' +
|
||||||
|
'<!-- Infinite loop to model Loop1 -->' +
|
||||||
|
'</Loop2>' +
|
||||||
|
'</Loop1>';
|
||||||
|
var schema = {
|
||||||
|
$ref: '#/definitions/Loop1'
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(sut.createSchemaXML('', schema, models)).to.equal(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('infinite loop Loop3 => Loop1, Loop1 => Loop2, Loop2 => Loop1', function () {
|
||||||
|
var expected = '<Loop3>' +
|
||||||
|
'<Loop1>' +
|
||||||
|
'<id>1</id>' +
|
||||||
|
'<Loop2>' +
|
||||||
|
'<id>1</id>' +
|
||||||
|
'<!-- Infinite loop to model Loop1 -->' +
|
||||||
|
'</Loop2>' +
|
||||||
|
'</Loop1>' +
|
||||||
|
'</Loop3>';
|
||||||
|
var schema = {
|
||||||
|
$ref: '#/definitions/Loop3'
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(sut.createSchemaXML('', schema, models)).to.equal(expected);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user