Change to fix the naming for elements for an array from the element name(XmlElement) defined with array rather than determining it from the element model definition(XmlRootElement)
This commit is contained in:
@@ -705,6 +705,18 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var getPrefix = function (name, xml) {
|
||||||
|
var result = name || '';
|
||||||
|
|
||||||
|
xml = xml || {};
|
||||||
|
|
||||||
|
if (xml.prefix) {
|
||||||
|
result = xml.prefix + ':' + result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
var getNamespace = function (xml) {
|
var getNamespace = function (xml) {
|
||||||
var namespace = '';
|
var namespace = '';
|
||||||
var name = 'xmlns';
|
var name = 'xmlns';
|
||||||
@@ -739,8 +751,12 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
var attributes = [];
|
var attributes = [];
|
||||||
|
|
||||||
if (!items) { return getErrorMessage(); }
|
if (!items) { return getErrorMessage(); }
|
||||||
|
var key = name;
|
||||||
value = createSchemaXML(name, items, models, config);
|
// If there is a name specified for the array elements, use that for the array elements name | https://github.com/swagger-api/swagger-ui/issues/2577
|
||||||
|
if(items.xml && items.xml.name) {
|
||||||
|
key = items.xml.name;
|
||||||
|
}
|
||||||
|
value = createSchemaXML(key, items, models, config);
|
||||||
|
|
||||||
if (namespace) {
|
if (namespace) {
|
||||||
attributes.push(namespace);
|
attributes.push(namespace);
|
||||||
@@ -872,6 +888,7 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
var output, index;
|
var output, index;
|
||||||
config = config || {};
|
config = config || {};
|
||||||
config.modelsToIgnore = config.modelsToIgnore || [];
|
config.modelsToIgnore = config.modelsToIgnore || [];
|
||||||
|
|
||||||
var descriptor = _.isString($ref) ? getDescriptorByRef($ref, name, models, config)
|
var descriptor = _.isString($ref) ? getDescriptorByRef($ref, name, models, config)
|
||||||
: getDescriptor(name, definition, models, config);
|
: getDescriptor(name, definition, models, config);
|
||||||
|
|
||||||
@@ -904,10 +921,10 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
if (arguments.length < 4) {
|
if (arguments.length < 4) {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.config = config || {};
|
this.config = config || {};
|
||||||
this.config.modelsToIgnore = this.config.modelsToIgnore || [];
|
this.config.modelsToIgnore = this.config.modelsToIgnore || [];
|
||||||
this.name = getName(name, definition.xml);
|
// name is already set by getDescriptorByRef or getDescriptor function depending on the type. Only prefix, if present is needed to be set here | https://github.com/swagger-api/swagger-ui/issues/2577
|
||||||
|
this.name = getPrefix(name, definition.xml);
|
||||||
this.definition = definition;
|
this.definition = definition;
|
||||||
this.models = models;
|
this.models = models;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@@ -917,7 +934,14 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
var modelType = simpleRef($ref);
|
var modelType = simpleRef($ref);
|
||||||
var model = models[modelType] || {};
|
var model = models[modelType] || {};
|
||||||
var type = model.definition && model.definition.type ? model.definition.type : 'object';
|
var type = model.definition && model.definition.type ? model.definition.type : 'object';
|
||||||
|
// If model definition xml name is present, then that will be preferred over model name. This is the case of preferring XmlElement name over XmlRootElement name if XmlElement name is provided | https://github.com/swagger-api/swagger-ui/issues/2577
|
||||||
|
if(model.definition.xml && model.definition.xml.name) {
|
||||||
|
name = name || model.definition.xml.name || model.name;
|
||||||
|
}
|
||||||
|
// else only model name will be considered for determination | https://github.com/swagger-api/swagger-ui/issues/2577
|
||||||
|
else {
|
||||||
name = name || model.name;
|
name = name || model.name;
|
||||||
|
}
|
||||||
|
|
||||||
if (config.modelsToIgnore.indexOf($ref) > -1) {
|
if (config.modelsToIgnore.indexOf($ref) > -1) {
|
||||||
type = 'loop';
|
type = 'loop';
|
||||||
@@ -929,13 +953,15 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
if (!model.definition) {
|
if (!model.definition) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Descriptor(name, type, model.definition, models, config);
|
return new Descriptor(name, type, model.definition, models, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDescriptor (name, definition, models, config){
|
function getDescriptor (name, definition, models, config){
|
||||||
var type = definition.type || 'object';
|
var type = definition.type || 'object';
|
||||||
|
// If definition xml name is present, then that will be preferred over name | https://github.com/swagger-api/swagger-ui/issues/2577
|
||||||
|
if(definition.xml && definition.xml.name) {
|
||||||
|
name = definition.xml.name || name;
|
||||||
|
}
|
||||||
if (!definition) {
|
if (!definition) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user