From 8155330ae32105edf73ab5eb763770bfca6c6375 Mon Sep 17 00:00:00 2001 From: Ritesh Garg Date: Thu, 22 Dec 2016 14:00:24 -0500 Subject: [PATCH 1/4] Change to set name for array elements from items.xml.name if it is set. Another issue after fixing this was for complex objects, that the name for element (from xmlelement annotation) was getting overridden by ref name (from xmlelementwrapper annotation) --- src/main/javascript/view/partials/signature.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/javascript/view/partials/signature.js b/src/main/javascript/view/partials/signature.js index c6ed5fab..97ed4b06 100644 --- a/src/main/javascript/view/partials/signature.js +++ b/src/main/javascript/view/partials/signature.js @@ -739,8 +739,14 @@ SwaggerUi.partials.signature = (function () { var attributes = []; if (!items) { return getErrorMessage(); } + + // To provide the name for the items from xml.name if it is provided | https://github.com/swagger-api/swagger-core/issues/2047 + var key = name; + if(items.xml != null && items.xml.name != null) { + key = items.xml.name; + } - value = createSchemaXML(name, items, models, config); + value = createSchemaXML(key, items, models, config); if (namespace) { attributes.push(namespace); @@ -841,6 +847,10 @@ SwaggerUi.partials.signature = (function () { } xml = prop.xml || {}; + // To provide the name for the object from xml.name if it is provided. If it is not, then it would be derived from the ref | https://github.com/swagger-api/swagger-core/issues/2047 + if(xml != null && xml.name != null) { + key = xml.name; + } result = createSchemaXML(key, prop, models, config); if (xml.attribute) { From 8b01247192391b70ddcd43bbaf95bf2fd482468e Mon Sep 17 00:00:00 2001 From: Ritesh Garg Date: Thu, 22 Dec 2016 14:00:24 -0500 Subject: [PATCH 2/4] 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) --- .../javascript/view/partials/signature.js | 48 ++++++++++++++----- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/src/main/javascript/view/partials/signature.js b/src/main/javascript/view/partials/signature.js index c6ed5fab..93ce3383 100644 --- a/src/main/javascript/view/partials/signature.js +++ b/src/main/javascript/view/partials/signature.js @@ -704,6 +704,18 @@ SwaggerUi.partials.signature = (function () { 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 namespace = ''; @@ -739,8 +751,12 @@ SwaggerUi.partials.signature = (function () { var attributes = []; if (!items) { return getErrorMessage(); } - - value = createSchemaXML(name, items, models, config); + var key = name; + // 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) { attributes.push(namespace); @@ -827,7 +843,7 @@ SwaggerUi.partials.signature = (function () { if (namespace) { attrs.push(namespace); - } + } if (!properties && !additionalProperties) { return getErrorMessage(); } @@ -872,9 +888,10 @@ SwaggerUi.partials.signature = (function () { var output, index; config = config || {}; config.modelsToIgnore = config.modelsToIgnore || []; + var descriptor = _.isString($ref) ? getDescriptorByRef($ref, name, models, config) : getDescriptor(name, definition, models, config); - + if (!descriptor) { return getErrorMessage(); } @@ -904,10 +921,10 @@ SwaggerUi.partials.signature = (function () { if (arguments.length < 4) { throw new Error(); } - this.config = config || {}; 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.models = models; this.type = type; @@ -917,8 +934,15 @@ SwaggerUi.partials.signature = (function () { var modelType = simpleRef($ref); var model = models[modelType] || {}; var type = model.definition && model.definition.type ? model.definition.type : 'object'; - name = name || model.name; - + // 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; + } + if (config.modelsToIgnore.indexOf($ref) > -1) { type = 'loop'; config.loopTo = modelType; @@ -929,13 +953,15 @@ SwaggerUi.partials.signature = (function () { if (!model.definition) { 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){ 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) { return null; } From d9e14e1e7dbab496239b339506dd6015d5a9ea49 Mon Sep 17 00:00:00 2001 From: Ritesh Garg Date: Fri, 23 Dec 2016 12:16:12 -0500 Subject: [PATCH 3/4] Commenting getName function as names are now determined beforehand and the prefix part is exposed as a separate function --- src/main/javascript/view/partials/signature.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/javascript/view/partials/signature.js b/src/main/javascript/view/partials/signature.js index 3dbacb1c..8566acf2 100644 --- a/src/main/javascript/view/partials/signature.js +++ b/src/main/javascript/view/partials/signature.js @@ -689,7 +689,8 @@ SwaggerUi.partials.signature = (function () { return str.join(''); }; - var getName = function (name, xml) { + // Commenting this funtion as the names are now determined beforehand and the prefix part is exposed as a separate function | https://github.com/swagger-api/swagger-ui/issues/2577 + /** var getName = function (name, xml) { var result = name || ''; xml = xml || {}; @@ -704,6 +705,7 @@ SwaggerUi.partials.signature = (function () { return result; }; + */ var getPrefix = function (name, xml) { var result = name || ''; From 1142f01da1ce1c23990c26d10e9e2d2275ae8d05 Mon Sep 17 00:00:00 2001 From: Ritesh Garg Date: Fri, 23 Dec 2016 20:02:24 -0500 Subject: [PATCH 4/4] Adding the check for model.definition --- src/main/javascript/view/partials/signature.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/javascript/view/partials/signature.js b/src/main/javascript/view/partials/signature.js index 8566acf2..4a2f516d 100644 --- a/src/main/javascript/view/partials/signature.js +++ b/src/main/javascript/view/partials/signature.js @@ -936,7 +936,7 @@ SwaggerUi.partials.signature = (function () { var model = models[modelType] || {}; 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) { + if(model.definition && 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