Skip to content

Commit c4e751f

Browse files
committed
swagger-api#1248 createXMLSample moved creating primitive xml into separate function
1 parent ae99828 commit c4e751f

File tree

2 files changed

+54
-35
lines changed

2 files changed

+54
-35
lines changed

swagger-ui.js

+53-34
Original file line numberDiff line numberDiff line change
@@ -26897,21 +26897,7 @@ SwaggerUi.partials.signature = (function () {
2689726897
return createXMLSample(name, model.definition, models);
2689826898
};
2689926899

26900-
function createObjectXML (name, properties, xml, models) {
26901-
var props;
26902-
26903-
if (!properties) { return ''; }
26904-
26905-
properties = properties || {};
26906-
26907-
props = _.map(properties, function (prop, key) {
26908-
return createXMLSample(key, prop, models);
26909-
}).join('');
26910-
26911-
return wrapTag(name, props);
26912-
}
26913-
26914-
function createXMLSample (name, definition, models) {
26900+
var createPrimitiveXML = function (name, definition) {
2691526901
var primitivesMap = {
2691626902
'string': {
2691726903
'date': new Date(1).toISOString().split('T')[0],
@@ -26928,40 +26914,73 @@ SwaggerUi.partials.signature = (function () {
2692826914
'default': true
2692926915
}
2693026916
};
26931-
var type = definition.type || 'object';
26917+
var type = definition.type;
2693226918
var format = definition.format;
26933-
var xml = definition.xml || {};
26919+
var namespace = getNamespace(definition.xml);
2693426920
var attributes = [];
26935-
var namespace = getNamespace(xml);
26936-
var $ref = definition.$ref;
2693726921
var value;
2693826922

26939-
if (_.isString($ref)) {
26940-
return getModelXML($ref, models);
26923+
if (_.keys(primitivesMap).indexOf(type) < 0) { return ''; }
26924+
26925+
if (namespace) {
26926+
attributes.push(namespace);
2694126927
}
2694226928

26943-
name = getName(name, xml);
26929+
if (_.isArray(definition.enum)){
26930+
value = definition.enum[0];
26931+
} else {
26932+
value = definition.example || primitivesMap[type][format] || primitivesMap[type].default;
26933+
}
26934+
26935+
return wrapTag(name, value, attributes);
26936+
};
26937+
26938+
function createObjectXML (name, properties, xml, models) {
26939+
var props;
26940+
var attrs = [];
26941+
var namespace = getNamespace(xml);
2694426942

2694526943
if (namespace) {
26946-
attributes.push(namespace);
26944+
attrs.push(namespace);
2694726945
}
2694826946

26947+
if (!properties) { return ''; }
2694926948

26950-
// Here are going to be else statements for Array and Object types
26951-
if (_.keys(primitivesMap).indexOf(type) !== -1) {
26952-
if (_.isArray(definition.enum)){
26953-
value = definition.enum[0];
26954-
} else {
26955-
value = definition.example || primitivesMap[type][format] || primitivesMap[type].default;
26956-
}
26957-
return wrapTag(name, value, attributes);
26958-
} else if (type === 'array') {
26949+
properties = properties || {};
26950+
26951+
props = _.map(properties, function (prop, key) {
26952+
return createXMLSample(key, prop, models);
26953+
}).join('');
26954+
26955+
return wrapTag(name, props);
26956+
}
26957+
26958+
function createXMLSample (name, definition, models) {
26959+
var type, xml, $ref;
26960+
26961+
if (arguments.length === 2) {
26962+
models = arguments[1];
26963+
definition = arguments[0];
26964+
name = '';
26965+
}
26966+
26967+
type = definition.type || 'object';
26968+
xml = definition.xml || {};
26969+
$ref = definition.$ref;
26970+
26971+
if (_.isString($ref)) {
26972+
return getModelXML($ref, models);
26973+
}
26974+
26975+
name = getName(name, xml);
26976+
26977+
if (type === 'array') {
2695926978
return createArrayXML(name, definition.items, xml, models);
2696026979
} else if (type === 'object') {
2696126980
return createObjectXML(name, definition.properties, xml, models);
26981+
} else {
26982+
return createPrimitiveXML(name, definition);
2696226983
}
26963-
26964-
return '';
2696526984
}
2696626985

2696726986
return {

0 commit comments

Comments
 (0)