#1248 createXMLSample added array

This commit is contained in:
Anna Bodnia
2016-01-13 12:30:12 +02:00
parent b3ddef2965
commit aa86bb5fe7
4 changed files with 117 additions and 5 deletions

22
dist/swagger-ui.js vendored
View File

@@ -26817,11 +26817,11 @@ SwaggerUi.partials.signature = (function () {
attributes = attrs.map(function (attr) { attributes = attrs.map(function (attr) {
return ' ' + attr.name + '="' + attr.value + '"'; return ' ' + attr.name + '="' + attr.value + '"';
}); }).join('');
str = [ str = [
'<', name, '<', name,
attributes.join(''), attributes,
'>', '>',
value, value,
'</', name, '>' '</', name, '>'
@@ -26868,6 +26868,22 @@ SwaggerUi.partials.signature = (function () {
}; };
}; };
var createArray = function (name, items, xml) {
var value;
if (!items) { return ''; }
value = createXMLSample(name, items) + createXMLSample(name, items);
xml = xml || {};
if (xml.wrapped) {
value = wrapTag(name, value);
}
return value;
};
var createXMLSample = function (name, definition) { var createXMLSample = function (name, definition) {
var primitivesMap = { var primitivesMap = {
'string': { 'string': {
@@ -26904,6 +26920,8 @@ SwaggerUi.partials.signature = (function () {
value = primitivesMap[type][format] || primitivesMap[type].default; value = primitivesMap[type][format] || primitivesMap[type].default;
return wrapTag(name, value, attributes); return wrapTag(name, value, attributes);
} else if (type === 'array') {
return createArray(name, definition.items, xml);
} }
return ''; return '';

File diff suppressed because one or more lines are too long

View File

@@ -650,11 +650,11 @@ SwaggerUi.partials.signature = (function () {
attributes = attrs.map(function (attr) { attributes = attrs.map(function (attr) {
return ' ' + attr.name + '="' + attr.value + '"'; return ' ' + attr.name + '="' + attr.value + '"';
}); }).join('');
str = [ str = [
'<', name, '<', name,
attributes.join(''), attributes,
'>', '>',
value, value,
'</', name, '>' '</', name, '>'
@@ -701,6 +701,22 @@ SwaggerUi.partials.signature = (function () {
}; };
}; };
var createArray = function (name, items, xml) {
var value;
if (!items) { return ''; }
value = createXMLSample(name, items) + createXMLSample(name, items);
xml = xml || {};
if (xml.wrapped) {
value = wrapTag(name, value);
}
return value;
};
var createXMLSample = function (name, definition) { var createXMLSample = function (name, definition) {
var primitivesMap = { var primitivesMap = {
'string': { 'string': {
@@ -737,6 +753,8 @@ SwaggerUi.partials.signature = (function () {
value = primitivesMap[type][format] || primitivesMap[type].default; value = primitivesMap[type][format] || primitivesMap[type].default;
return wrapTag(name, value, attributes); return wrapTag(name, value, attributes);
} else if (type === 'array') {
return createArray(name, definition.items, xml);
} }
return ''; return '';

View File

@@ -114,5 +114,81 @@ 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)).to.equal('<name xlmns="http://swagger.io/schema/sample">string</name>');
}); });
}); });
describe('array', function () {
it('returns tag <tagname>string</tagname><tagname>string</tagname> when passing string items', function () {
var expected = '<tagname>string</tagname><tagname>string</tagname>';
var name = 'tagname';
var definition = {
type: 'array',
items: {
type: 'string'
}
};
expect(sut.createXMLSample(name, definition)).to.equal(expected);
});
});
describe('array', function () {
it('returns tag <animal>string</animal><animal>string</animal> when passing string items with name', function () {
var expected = '<animal>string</animal><animal>string</animal>';
var name = 'animals';
var definition = {
type: 'array',
items: {
type: 'string',
xml: {
name: 'animal'
}
}
};
expect(sut.createXMLSample(name, definition)).to.equal(expected);
});
});
describe('array', function () {
it('returns tag <animals><animal>string</animal><animal>string</animal></animals> when passing string items with name', function () {
var expected = '<animals><animal>string</animal><animal>string</animal></animals>';
var name = 'animals';
var definition = {
type: 'array',
items: {
type: 'string',
xml: {
name: 'animal'
}
},
xml: {
wrapped: true
}
};
expect(sut.createXMLSample(name, definition)).to.equal(expected);
});
});
describe('array', function () {
it('returns tag <aliens><animal>string</animal><animal>string</animal></aliens> when passing string items with name and {wrapped: true}', function () {
var expected = '<aliens><animal>string</animal><animal>string</animal></aliens>';
var name = 'animals';
var definition = {
type: 'array',
items: {
type: 'string',
xml: {
name: 'animal'
}
},
xml: {
wrapped: true,
name: 'aliens'
}
};
expect(sut.createXMLSample(name, definition)).to.equal(expected);
});
});
}); });
}); });