Skip to content

Commit 048645e

Browse files
committed
swagger-api#1248 createXMLSample added error message
1 parent c395b97 commit 048645e

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

swagger-ui.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26882,9 +26882,9 @@ SwaggerUi.partials.signature = (function () {
2688226882
var items = definition.items;
2688326883
var xml = definition.xml || {};
2688426884

26885-
if (!items) { return ''; }
26885+
if (!items) { return getErrorMessage(); }
2688626886

26887-
value = createXMLSample(name, items, models);
26887+
value = createSchemaXML(name, items, models);
2688826888
value += value;
2688926889

2689026890
xml = xml || {};
@@ -26901,11 +26901,9 @@ SwaggerUi.partials.signature = (function () {
2690126901
var model = models[type] || {};
2690226902
var name = model.name || modelType;
2690326903

26904-
if (!model.definition) {
26905-
return '';
26906-
}
26904+
if (!model.definition) { return getErrorMessage(); }
2690726905

26908-
return createXMLSample(name, model.definition, models);
26906+
return createSchemaXML(name, model.definition, models);
2690926907
};
2691026908

2691126909
var createPrimitiveXML = function (name, definition) {
@@ -26931,7 +26929,7 @@ SwaggerUi.partials.signature = (function () {
2693126929
var attributes = [];
2693226930
var value;
2693326931

26934-
if (_.keys(primitivesMap).indexOf(type) < 0) { return ''; }
26932+
if (_.keys(primitivesMap).indexOf(type) < 0) { return getErrorMessage(); }
2693526933

2693626934
if (namespace) {
2693726935
attributes.push(namespace);
@@ -26947,7 +26945,7 @@ SwaggerUi.partials.signature = (function () {
2694726945
};
2694826946

2694926947
function createObjectXML (name, definition, models) {
26950-
var props;
26948+
var serializedProperties;
2695126949
var attrs = [];
2695226950
var properties = definition.properties;
2695326951
var additionalProperties = definition.additionalProperties;
@@ -26958,31 +26956,24 @@ SwaggerUi.partials.signature = (function () {
2695826956
attrs.push(namespace);
2695926957
}
2696026958

26961-
if (!properties && !additionalProperties) { return ''; }
26959+
if (!properties && !additionalProperties) { return getErrorMessage(); }
2696226960

2696326961
properties = properties || {};
2696426962

26965-
props = _.map(properties, function (prop, key) {
26966-
return createXMLSample(key, prop, models);
26963+
serializedProperties = _.map(properties, function (prop, key) {
26964+
return createSchemaXML(key, prop, models);
2696726965
}).join('');
2696826966

2696926967
if (additionalProperties) {
26970-
props += '<!-- additional elements allowed -->';
26968+
serializedProperties += '<!-- additional elements allowed -->';
2697126969
}
2697226970

26973-
return wrapTag(name, props, attrs);
26971+
return wrapTag(name, serializedProperties, attrs);
2697426972
}
2697526973

26976-
function createXMLSample (name, definition, models) {
26974+
function createSchemaXML (name, definition, models) {
2697726975
var type, xml, $ref;
2697826976

26979-
// allow ingnoring 'name' parameter
26980-
if (arguments.length === 2) {
26981-
models = arguments[1];
26982-
definition = arguments[0];
26983-
name = '';
26984-
}
26985-
2698626977
type = definition.type || 'object';
2698726978
xml = definition.xml || {};
2698826979
$ref = definition.$ref;
@@ -27002,11 +26993,22 @@ SwaggerUi.partials.signature = (function () {
2700226993
}
2700326994
}
2700426995

26996+
function getErrorMessage () {
26997+
return '<!-- invalid XML -->';
26998+
}
26999+
27000+
function createXMLSample (definition, models) {
27001+
var prolog = '<?xml version="1.0"?>';
27002+
27003+
return prolog + createSchemaXML('', definition, models);
27004+
}
27005+
2700527006
return {
2700627007
getModelSignature: getModelSignature,
2700727008
createJSONSample: createJSONSample,
2700827009
getParameterModelSignature: getParameterModelSignature,
2700927010
createParameterJSONSample: createParameterJSONSample,
27011+
createSchemaXML: createSchemaXML,
2701027012
createXMLSample: createXMLSample
2701127013
};
2701227014

0 commit comments

Comments
 (0)