#1248 createXMLSample added object xml representation

This commit is contained in:
Anna Bodnia
2016-01-13 17:13:42 +02:00
parent 455c82c13b
commit 8917a9bf76
4 changed files with 169 additions and 15 deletions

29
dist/swagger-ui.js vendored
View File

@@ -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,

File diff suppressed because one or more lines are too long

View File

@@ -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,

View File

@@ -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);
});
});
});
});