#1248 createXMLSample moved creating primitive xml into separate function
This commit is contained in:
89
dist/swagger-ui.js
vendored
89
dist/swagger-ui.js
vendored
@@ -26897,21 +26897,7 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
return createXMLSample(name, model.definition, models);
|
return createXMLSample(name, model.definition, models);
|
||||||
};
|
};
|
||||||
|
|
||||||
function createObjectXML (name, properties, xml, models) {
|
var createPrimitiveXML = function (name, definition) {
|
||||||
var props;
|
|
||||||
|
|
||||||
if (!properties) { return ''; }
|
|
||||||
|
|
||||||
properties = properties || {};
|
|
||||||
|
|
||||||
props = _.map(properties, function (prop, key) {
|
|
||||||
return createXMLSample(key, prop, models);
|
|
||||||
}).join('');
|
|
||||||
|
|
||||||
return wrapTag(name, props);
|
|
||||||
}
|
|
||||||
|
|
||||||
function createXMLSample (name, definition, models) {
|
|
||||||
var primitivesMap = {
|
var primitivesMap = {
|
||||||
'string': {
|
'string': {
|
||||||
'date': new Date(1).toISOString().split('T')[0],
|
'date': new Date(1).toISOString().split('T')[0],
|
||||||
@@ -26928,40 +26914,73 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
'default': true
|
'default': true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var type = definition.type || 'object';
|
var type = definition.type;
|
||||||
var format = definition.format;
|
var format = definition.format;
|
||||||
var xml = definition.xml || {};
|
var namespace = getNamespace(definition.xml);
|
||||||
var attributes = [];
|
var attributes = [];
|
||||||
var namespace = getNamespace(xml);
|
|
||||||
var $ref = definition.$ref;
|
|
||||||
var value;
|
var value;
|
||||||
|
|
||||||
|
if (_.keys(primitivesMap).indexOf(type) < 0) { return ''; }
|
||||||
|
|
||||||
|
if (namespace) {
|
||||||
|
attributes.push(namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_.isArray(definition.enum)){
|
||||||
|
value = definition.enum[0];
|
||||||
|
} else {
|
||||||
|
value = definition.example || primitivesMap[type][format] || primitivesMap[type].default;
|
||||||
|
}
|
||||||
|
|
||||||
|
return wrapTag(name, value, attributes);
|
||||||
|
};
|
||||||
|
|
||||||
|
function createObjectXML (name, properties, xml, models) {
|
||||||
|
var props;
|
||||||
|
var attrs = [];
|
||||||
|
var namespace = getNamespace(xml);
|
||||||
|
|
||||||
|
if (namespace) {
|
||||||
|
attrs.push(namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!properties) { return ''; }
|
||||||
|
|
||||||
|
properties = properties || {};
|
||||||
|
|
||||||
|
props = _.map(properties, function (prop, key) {
|
||||||
|
return createXMLSample(key, prop, models);
|
||||||
|
}).join('');
|
||||||
|
|
||||||
|
return wrapTag(name, props);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createXMLSample (name, definition, models) {
|
||||||
|
var type, xml, $ref;
|
||||||
|
|
||||||
|
if (arguments.length === 2) {
|
||||||
|
models = arguments[1];
|
||||||
|
definition = arguments[0];
|
||||||
|
name = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
type = definition.type || 'object';
|
||||||
|
xml = definition.xml || {};
|
||||||
|
$ref = definition.$ref;
|
||||||
|
|
||||||
if (_.isString($ref)) {
|
if (_.isString($ref)) {
|
||||||
return getModelXML($ref, models);
|
return getModelXML($ref, models);
|
||||||
}
|
}
|
||||||
|
|
||||||
name = getName(name, xml);
|
name = getName(name, xml);
|
||||||
|
|
||||||
if (namespace) {
|
if (type === 'array') {
|
||||||
attributes.push(namespace);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Here are going to be else statements for Array and Object types
|
|
||||||
if (_.keys(primitivesMap).indexOf(type) !== -1) {
|
|
||||||
if (_.isArray(definition.enum)){
|
|
||||||
value = definition.enum[0];
|
|
||||||
} else {
|
|
||||||
value = definition.example || primitivesMap[type][format] || primitivesMap[type].default;
|
|
||||||
}
|
|
||||||
return wrapTag(name, value, attributes);
|
|
||||||
} else if (type === 'array') {
|
|
||||||
return createArrayXML(name, definition.items, xml, models);
|
return createArrayXML(name, definition.items, xml, models);
|
||||||
} else if (type === 'object') {
|
} else if (type === 'object') {
|
||||||
return createObjectXML(name, definition.properties, xml, models);
|
return createObjectXML(name, definition.properties, xml, models);
|
||||||
|
} else {
|
||||||
|
return createPrimitiveXML(name, definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
2
dist/swagger-ui.min.js
vendored
2
dist/swagger-ui.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -730,21 +730,7 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
return createXMLSample(name, model.definition, models);
|
return createXMLSample(name, model.definition, models);
|
||||||
};
|
};
|
||||||
|
|
||||||
function createObjectXML (name, properties, xml, models) {
|
var createPrimitiveXML = function (name, definition) {
|
||||||
var props;
|
|
||||||
|
|
||||||
if (!properties) { return ''; }
|
|
||||||
|
|
||||||
properties = properties || {};
|
|
||||||
|
|
||||||
props = _.map(properties, function (prop, key) {
|
|
||||||
return createXMLSample(key, prop, models);
|
|
||||||
}).join('');
|
|
||||||
|
|
||||||
return wrapTag(name, props);
|
|
||||||
}
|
|
||||||
|
|
||||||
function createXMLSample (name, definition, models) {
|
|
||||||
var primitivesMap = {
|
var primitivesMap = {
|
||||||
'string': {
|
'string': {
|
||||||
'date': new Date(1).toISOString().split('T')[0],
|
'date': new Date(1).toISOString().split('T')[0],
|
||||||
@@ -761,40 +747,74 @@ SwaggerUi.partials.signature = (function () {
|
|||||||
'default': true
|
'default': true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var type = definition.type || 'object';
|
var type = definition.type;
|
||||||
var format = definition.format;
|
var format = definition.format;
|
||||||
var xml = definition.xml || {};
|
var namespace = getNamespace(definition.xml);
|
||||||
var attributes = [];
|
var attributes = [];
|
||||||
var namespace = getNamespace(xml);
|
|
||||||
var $ref = definition.$ref;
|
|
||||||
var value;
|
var value;
|
||||||
|
|
||||||
|
if (_.keys(primitivesMap).indexOf(type) < 0) { return ''; }
|
||||||
|
|
||||||
|
if (namespace) {
|
||||||
|
attributes.push(namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_.isArray(definition.enum)){
|
||||||
|
value = definition.enum[0];
|
||||||
|
} else {
|
||||||
|
value = definition.example || primitivesMap[type][format] || primitivesMap[type].default;
|
||||||
|
}
|
||||||
|
|
||||||
|
return wrapTag(name, value, attributes);
|
||||||
|
};
|
||||||
|
|
||||||
|
function createObjectXML (name, properties, xml, models) {
|
||||||
|
var props;
|
||||||
|
var attrs = [];
|
||||||
|
var namespace = getNamespace(xml);
|
||||||
|
|
||||||
|
if (namespace) {
|
||||||
|
attrs.push(namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!properties) { return ''; }
|
||||||
|
|
||||||
|
properties = properties || {};
|
||||||
|
|
||||||
|
props = _.map(properties, function (prop, key) {
|
||||||
|
return createXMLSample(key, prop, models);
|
||||||
|
}).join('');
|
||||||
|
|
||||||
|
return wrapTag(name, props);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createXMLSample (name, definition, models) {
|
||||||
|
var type, xml, $ref;
|
||||||
|
|
||||||
|
// allow ingnoring 'name' parameter
|
||||||
|
if (arguments.length === 2) {
|
||||||
|
models = arguments[1];
|
||||||
|
definition = arguments[0];
|
||||||
|
name = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
type = definition.type || 'object';
|
||||||
|
xml = definition.xml || {};
|
||||||
|
$ref = definition.$ref;
|
||||||
|
|
||||||
if (_.isString($ref)) {
|
if (_.isString($ref)) {
|
||||||
return getModelXML($ref, models);
|
return getModelXML($ref, models);
|
||||||
}
|
}
|
||||||
|
|
||||||
name = getName(name, xml);
|
name = getName(name, xml);
|
||||||
|
|
||||||
if (namespace) {
|
if (type === 'array') {
|
||||||
attributes.push(namespace);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Here are going to be else statements for Array and Object types
|
|
||||||
if (_.keys(primitivesMap).indexOf(type) !== -1) {
|
|
||||||
if (_.isArray(definition.enum)){
|
|
||||||
value = definition.enum[0];
|
|
||||||
} else {
|
|
||||||
value = definition.example || primitivesMap[type][format] || primitivesMap[type].default;
|
|
||||||
}
|
|
||||||
return wrapTag(name, value, attributes);
|
|
||||||
} else if (type === 'array') {
|
|
||||||
return createArrayXML(name, definition.items, xml, models);
|
return createArrayXML(name, definition.items, xml, models);
|
||||||
} else if (type === 'object') {
|
} else if (type === 'object') {
|
||||||
return createObjectXML(name, definition.properties, xml, models);
|
return createObjectXML(name, definition.properties, xml, models);
|
||||||
|
} else {
|
||||||
|
return createPrimitiveXML(name, definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -73,42 +73,42 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
var name = 'tagname';
|
var name = 'tagname';
|
||||||
var definition = {type: 'string'};
|
var definition = {type: 'string'};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal('<tagname>string</tagname>');
|
expect(sut.createXMLSample(name, definition, models)).to.equal('<tagname>string</tagname>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns tag <tagname>1</tagname> when passing type integer', function () {
|
it('returns tag <tagname>1</tagname> when passing type integer', function () {
|
||||||
var name = 'tagname';
|
var name = 'tagname';
|
||||||
var definition = {type: 'integer'};
|
var definition = {type: 'integer'};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal('<tagname>1</tagname>');
|
expect(sut.createXMLSample(name, definition, models)).to.equal('<tagname>1</tagname>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns tag <tagname>1.1</tagname> when passing type number', function () {
|
it('returns tag <tagname>1.1</tagname> when passing type number', function () {
|
||||||
var name = 'tagname';
|
var name = 'tagname';
|
||||||
var definition = {type: 'number'};
|
var definition = {type: 'number'};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal('<tagname>1.1</tagname>');
|
expect(sut.createXMLSample(name, definition, models)).to.equal('<tagname>1.1</tagname>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns tag <tagname>boolean</tagname> when passing type boolean', function () {
|
it('returns tag <tagname>boolean</tagname> when passing type boolean', function () {
|
||||||
var name = 'tagname';
|
var name = 'tagname';
|
||||||
var definition = {type: 'boolean'};
|
var definition = {type: 'boolean'};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal('<tagname>true</tagname>');
|
expect(sut.createXMLSample(name, definition, models)).to.equal('<tagname>true</tagname>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns tag <tagname>' + date + '</tagname> when passing type string format date', function () {
|
it('returns tag <tagname>' + date + '</tagname> when passing type string format date', function () {
|
||||||
var name = 'tagname';
|
var name = 'tagname';
|
||||||
var definition = {type: 'string', format: 'date'};
|
var definition = {type: 'string', format: 'date'};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal('<tagname>' + date + '</tagname>');
|
expect(sut.createXMLSample(name, definition, models)).to.equal('<tagname>' + date + '</tagname>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns tag <tagname>' + dateTime + '</tagname> when passing type string format date-time', function () {
|
it('returns tag <tagname>' + dateTime + '</tagname> when passing type string format date-time', function () {
|
||||||
var name = 'tagname';
|
var name = 'tagname';
|
||||||
var definition = {type: 'string', format: 'date-time'};
|
var definition = {type: 'string', format: 'date-time'};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal('<tagname>' + dateTime + '</tagname>');
|
expect(sut.createXMLSample(name, definition, models)).to.equal('<tagname>' + dateTime + '</tagname>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal('<newtagname>string</newtagname>');
|
expect(sut.createXMLSample(name, definition, models)).to.equal('<newtagname>string</newtagname>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns tag <test:newtagname>string</test:newtagname> when passing type string and xml:{name: "newtagname", prefix:"test"}', function () {
|
it('returns tag <test:newtagname>string</test:newtagname> when passing type string and xml:{name: "newtagname", prefix:"test"}', function () {
|
||||||
@@ -135,7 +135,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal('<test:newtagname>string</test:newtagname>');
|
expect(sut.createXMLSample(name, definition, models)).to.equal('<test:newtagname>string</test:newtagname>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns tag <test:tagname>string</test:tagname> when passing type string and xml:{name: "newtagname", prefix:"test"}', function () {
|
it('returns tag <test:tagname>string</test:tagname> when passing type string and xml:{name: "newtagname", prefix:"test"}', function () {
|
||||||
@@ -147,7 +147,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal('<test:tagname>string</test:tagname>');
|
expect(sut.createXMLSample(name, definition, models)).to.equal('<test:tagname>string</test:tagname>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns tag <test:tagname >string</test:tagname> when passing type string and xml:{"namespace": "http://swagger.io/schema/sample", "prefix": "sample"}', function () {
|
it('returns tag <test:tagname >string</test:tagname> when passing type string and xml:{"namespace": "http://swagger.io/schema/sample", "prefix": "sample"}', function () {
|
||||||
@@ -160,7 +160,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal('<sample:name xlmns:sample="http://swagger.io/schema/sample">string</sample:name>');
|
expect(sut.createXMLSample(name, definition, models)).to.equal('<sample:name xlmns:sample="http://swagger.io/schema/sample">string</sample:name>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns tag <test:tagname >string</test:tagname> when passing type string and xml:{"namespace": "http://swagger.io/schema/sample"}', function () {
|
it('returns tag <test:tagname >string</test:tagname> when passing type string and xml:{"namespace": "http://swagger.io/schema/sample"}', function () {
|
||||||
@@ -172,7 +172,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal('<name xlmns="http://swagger.io/schema/sample">string</name>');
|
expect(sut.createXMLSample(name, definition, models)).to.equal('<name xlmns="http://swagger.io/schema/sample">string</name>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal(expected);
|
expect(sut.createXMLSample(name, definition, models)).to.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns tag <animal>string</animal><animal>string</animal> when passing string items with name', function () {
|
it('returns tag <animal>string</animal><animal>string</animal> when passing string items with name', function () {
|
||||||
@@ -203,7 +203,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal(expected);
|
expect(sut.createXMLSample(name, definition, models)).to.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns tag <animals><animal>string</animal><animal>string</animal></animals> when passing string items with name', function () {
|
it('returns tag <animals><animal>string</animal><animal>string</animal></animals> when passing string items with name', function () {
|
||||||
@@ -222,7 +222,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal(expected);
|
expect(sut.createXMLSample(name, definition, models)).to.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns tag <aliens><animal>string</animal><animal>string</animal></aliens> when passing string items with name and {wrapped: true}', function () {
|
it('returns tag <aliens><animal>string</animal><animal>string</animal></aliens> when passing string items with name and {wrapped: true}', function () {
|
||||||
@@ -242,7 +242,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal(expected);
|
expect(sut.createXMLSample(name, definition, models)).to.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('return correct nested wrapped array', function () {
|
it('return correct nested wrapped array', function () {
|
||||||
@@ -265,7 +265,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal(expected);
|
expect(sut.createXMLSample(name, definition, models)).to.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('return correct nested wrapped array', function () {
|
it('return correct nested wrapped array', function () {
|
||||||
@@ -295,7 +295,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal(expected);
|
expect(sut.createXMLSample(name, definition, models)).to.equal(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -321,7 +321,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal(expected);
|
expect(sut.createXMLSample(name, definition, models)).to.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns object with integer property and array property', function () {
|
it('returns object with integer property and array property', function () {
|
||||||
@@ -349,7 +349,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal(expected);
|
expect(sut.createXMLSample(name, definition, models)).to.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns object with integer property and array property', function () {
|
it('returns object with integer property and array property', function () {
|
||||||
@@ -382,7 +382,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal(expected);
|
expect(sut.createXMLSample(name, definition, models)).to.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns nested objects', function () {
|
it('returns nested objects', function () {
|
||||||
@@ -416,7 +416,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample(name, definition)).to.equal(expected);
|
expect(sut.createXMLSample(name, definition, models)).to.equal(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -438,7 +438,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample('', schema, models)).to.equal(expected);
|
expect(sut.createXMLSample(schema, models)).to.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns Object with properties Pet and name', function () {
|
it('returns Object with properties Pet and name', function () {
|
||||||
@@ -463,7 +463,7 @@ describe('SwaggerUi.partials.signature tests', function () {
|
|||||||
$ref: '#/definitions/Pet'
|
$ref: '#/definitions/Pet'
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(sut.createXMLSample('', schema, models)).to.equal(expected);
|
expect(sut.createXMLSample(schema, models)).to.equal(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user