#1248 createXMLSample added object xml representation
This commit is contained in:
29
dist/swagger-ui.js
vendored
29
dist/swagger-ui.js
vendored
@@ -26868,7 +26868,7 @@ SwaggerUi.partials.signature = (function () {
|
||||
};
|
||||
};
|
||||
|
||||
var createArray = function (name, items, xml) {
|
||||
var createArrayXML = function (name, items, xml) {
|
||||
var value;
|
||||
|
||||
if (!items) { return ''; }
|
||||
@@ -26884,7 +26884,21 @@ SwaggerUi.partials.signature = (function () {
|
||||
return value;
|
||||
};
|
||||
|
||||
var createXMLSample = function (name, definition) {
|
||||
function createObjectXML (name, properties, xml) {
|
||||
var props;
|
||||
|
||||
if (!properties) { return ''; }
|
||||
|
||||
properties = properties || {};
|
||||
|
||||
props = _.map(properties, function (prop, key) {
|
||||
return createXMLSample(key, prop);
|
||||
}).join('');
|
||||
|
||||
return wrapTag(name, props);
|
||||
}
|
||||
|
||||
function createXMLSample (name, definition) {
|
||||
var primitivesMap = {
|
||||
'string': {
|
||||
'date': new Date(1).toISOString().split('T')[0],
|
||||
@@ -26901,7 +26915,7 @@ SwaggerUi.partials.signature = (function () {
|
||||
'default': true
|
||||
}
|
||||
};
|
||||
var type = definition.type;
|
||||
var type = definition.type || 'object';
|
||||
var format = definition.format;
|
||||
var xml = definition.xml || {};
|
||||
var attributes = [];
|
||||
@@ -26917,15 +26931,16 @@ SwaggerUi.partials.signature = (function () {
|
||||
|
||||
// Here are going to be else statements for Array and Object types
|
||||
if (_.keys(primitivesMap).indexOf(type) !== -1) {
|
||||
value = primitivesMap[type][format] || primitivesMap[type].default;
|
||||
|
||||
value = definition.example || primitivesMap[type][format] || primitivesMap[type].default;
|
||||
return wrapTag(name, value, attributes);
|
||||
} else if (type === 'array') {
|
||||
return createArray(name, definition.items, xml);
|
||||
return createArrayXML(name, definition.items, xml);
|
||||
} else if (type === 'object') {
|
||||
return createObjectXML(name, definition.properties, xml);
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
getModelSignature: getModelSignature,
|
||||
|
||||
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
@@ -701,7 +701,7 @@ SwaggerUi.partials.signature = (function () {
|
||||
};
|
||||
};
|
||||
|
||||
var createArray = function (name, items, xml) {
|
||||
var createArrayXML = function (name, items, xml) {
|
||||
var value;
|
||||
|
||||
if (!items) { return ''; }
|
||||
@@ -717,7 +717,21 @@ SwaggerUi.partials.signature = (function () {
|
||||
return value;
|
||||
};
|
||||
|
||||
var createXMLSample = function (name, definition) {
|
||||
function createObjectXML (name, properties, xml) {
|
||||
var props;
|
||||
|
||||
if (!properties) { return ''; }
|
||||
|
||||
properties = properties || {};
|
||||
|
||||
props = _.map(properties, function (prop, key) {
|
||||
return createXMLSample(key, prop);
|
||||
}).join('');
|
||||
|
||||
return wrapTag(name, props);
|
||||
}
|
||||
|
||||
function createXMLSample (name, definition) {
|
||||
var primitivesMap = {
|
||||
'string': {
|
||||
'date': new Date(1).toISOString().split('T')[0],
|
||||
@@ -734,7 +748,7 @@ SwaggerUi.partials.signature = (function () {
|
||||
'default': true
|
||||
}
|
||||
};
|
||||
var type = definition.type;
|
||||
var type = definition.type || 'object';
|
||||
var format = definition.format;
|
||||
var xml = definition.xml || {};
|
||||
var attributes = [];
|
||||
@@ -750,15 +764,16 @@ SwaggerUi.partials.signature = (function () {
|
||||
|
||||
// Here are going to be else statements for Array and Object types
|
||||
if (_.keys(primitivesMap).indexOf(type) !== -1) {
|
||||
value = primitivesMap[type][format] || primitivesMap[type].default;
|
||||
|
||||
value = definition.example || primitivesMap[type][format] || primitivesMap[type].default;
|
||||
return wrapTag(name, value, attributes);
|
||||
} else if (type === 'array') {
|
||||
return createArray(name, definition.items, xml);
|
||||
return createArrayXML(name, definition.items, xml);
|
||||
} else if (type === 'object') {
|
||||
return createObjectXML(name, definition.properties, xml);
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
getModelSignature: getModelSignature,
|
||||
|
||||
@@ -239,5 +239,129 @@ describe('SwaggerUi.partials.signature tests', function () {
|
||||
expect(sut.createXMLSample(name, definition)).to.equal(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('object', function () {
|
||||
it('returns object with 2 properties', function () {
|
||||
var expected = '<aliens>' +
|
||||
'<alien>string</alien>' +
|
||||
'<cat>1</cat>' +
|
||||
'</aliens>';
|
||||
var name = 'animals';
|
||||
var definition = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
alien: {
|
||||
type: 'string'
|
||||
},
|
||||
cat: {
|
||||
type: 'integer'
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: 'aliens'
|
||||
}
|
||||
};
|
||||
|
||||
expect(sut.createXMLSample(name, definition)).to.equal(expected);
|
||||
});
|
||||
|
||||
it('returns object with integer property and array property', function () {
|
||||
var expected = '<animals>' +
|
||||
'<aliens>string</aliens>' +
|
||||
'<aliens>string</aliens>' +
|
||||
'<cat>1</cat>' +
|
||||
'</animals>';
|
||||
var name = 'animals';
|
||||
var definition = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
aliens: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string'
|
||||
}
|
||||
},
|
||||
cat: {
|
||||
type: 'integer'
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: 'animals'
|
||||
}
|
||||
};
|
||||
|
||||
expect(sut.createXMLSample(name, definition)).to.equal(expected);
|
||||
});
|
||||
|
||||
it('returns object with integer property and array property', function () {
|
||||
var expected = '<animals>' +
|
||||
'<aliens><alien>string</alien><alien>string</alien></aliens>' +
|
||||
'<cat>1</cat>' +
|
||||
'</animals>';
|
||||
var name = 'animals';
|
||||
var definition = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
aliens: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
xml: {
|
||||
name: 'alien'
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
wrapped: true
|
||||
}
|
||||
},
|
||||
cat: {
|
||||
type: 'integer'
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: 'animals'
|
||||
}
|
||||
};
|
||||
|
||||
expect(sut.createXMLSample(name, definition)).to.equal(expected);
|
||||
});
|
||||
|
||||
it('returns nested objects', function () {
|
||||
var expected = '<animals>' +
|
||||
'<aliens>' +
|
||||
'<alien>string</alien>' +
|
||||
'</aliens>' +
|
||||
'<cat>string</cat>' +
|
||||
'</animals>';
|
||||
var name = 'animals';
|
||||
var definition = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
aliens: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
alien: {
|
||||
type: 'string',
|
||||
xml: {
|
||||
name: 'alien'
|
||||
}
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
wrapped: true
|
||||
}
|
||||
},
|
||||
cat: {
|
||||
type: 'string'
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: 'animals'
|
||||
}
|
||||
};
|
||||
|
||||
expect(sut.createXMLSample(name, definition)).to.equal(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user