#1892 infinite loop when rendering self-references
This commit is contained in:
@@ -712,6 +712,7 @@ SwaggerUi.partials.signature = (function () {
|
||||
|
||||
var createArrayXML = function (descriptor) {
|
||||
var name = descriptor.name;
|
||||
var config = descriptor.config;
|
||||
var definition = descriptor.definition;
|
||||
var models = descriptor.models;
|
||||
var value;
|
||||
@@ -720,7 +721,7 @@ SwaggerUi.partials.signature = (function () {
|
||||
|
||||
if (!items) { return getErrorMessage(); }
|
||||
|
||||
value = createSchemaXML(name, items, models);
|
||||
value = createSchemaXML(name, items, models, config);
|
||||
|
||||
xml = xml || {};
|
||||
|
||||
@@ -779,8 +780,9 @@ SwaggerUi.partials.signature = (function () {
|
||||
function createObjectXML (descriptor) {
|
||||
var name = descriptor.name;
|
||||
var definition = descriptor.definition;
|
||||
var config = descriptor.config;
|
||||
var models = descriptor.models;
|
||||
var isParam = descriptor.isParam;
|
||||
var isParam = descriptor.config.isParam;
|
||||
var serializedProperties;
|
||||
var attrs = [];
|
||||
var properties = definition.properties;
|
||||
@@ -799,10 +801,12 @@ SwaggerUi.partials.signature = (function () {
|
||||
serializedProperties = _.map(properties, function (prop, key) {
|
||||
var xml, result;
|
||||
|
||||
if (isParam && prop.readOnly) { return ''; }
|
||||
if (isParam && prop.readOnly) {
|
||||
return '';
|
||||
}
|
||||
|
||||
xml = prop.xml || {};
|
||||
result = createSchemaXML(key, prop, models);
|
||||
result = createSchemaXML(key, prop, models, config);
|
||||
|
||||
if (xml.attribute) {
|
||||
attrs.push(result);
|
||||
@@ -819,14 +823,18 @@ SwaggerUi.partials.signature = (function () {
|
||||
return wrapTag(name, serializedProperties, attrs);
|
||||
}
|
||||
|
||||
function getInfiniteLoopMessage (name) {
|
||||
return '<!-- Infinite loop to model ' + name + ' -->';
|
||||
}
|
||||
|
||||
function getErrorMessage () {
|
||||
return '<!-- invalid XML -->';
|
||||
}
|
||||
|
||||
function createSchemaXML (name, definition, models, isParam) {
|
||||
function createSchemaXML (name, definition, models, config) {
|
||||
var $ref = definition.$ref;
|
||||
var descriptor = _.isString($ref) ? getDescriptorByRef($ref, models)
|
||||
: getDescriptor(name, definition, models, isParam);
|
||||
var descriptor = _.isString($ref) ? getDescriptorByRef($ref, models, config)
|
||||
: getDescriptor(name, definition, models, config);
|
||||
|
||||
if (!descriptor) {
|
||||
return getErrorMessage();
|
||||
@@ -837,37 +845,48 @@ SwaggerUi.partials.signature = (function () {
|
||||
return createArrayXML(descriptor);
|
||||
case 'object':
|
||||
return createObjectXML(descriptor);
|
||||
case 'loop':
|
||||
return getInfiniteLoopMessage(descriptor.name);
|
||||
default:
|
||||
return createPrimitiveXML(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
function Descriptor (name, type, definition, models, isParam) {
|
||||
function Descriptor (name, type, definition, models, config) {
|
||||
if (arguments.length < 4) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
this.config = config || {};
|
||||
this.config.modelsToIgnore = this.config.modelsToIgnore || [];
|
||||
this.name = name;
|
||||
this.definition = definition;
|
||||
this.models = models;
|
||||
this.type = type;
|
||||
this.isParam = isParam;
|
||||
}
|
||||
|
||||
function getDescriptorByRef($ref, models) {
|
||||
function getDescriptorByRef($ref, models, config) {
|
||||
var modelType = simpleRef($ref);
|
||||
var model = models[modelType] || {};
|
||||
var name = model.name || modelType;
|
||||
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) {
|
||||
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 xml = definition.xml || {};
|
||||
|
||||
@@ -877,13 +896,13 @@ SwaggerUi.partials.signature = (function () {
|
||||
|
||||
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) {
|
||||
var prolog = '<?xml version="1.0"?>';
|
||||
|
||||
return formatXml(prolog + createSchemaXML('', definition, models, isParam));
|
||||
return formatXml(prolog + createSchemaXML('', definition, models, { isParam: isParam } ));
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user