#1248 implemented display property as attribute

This commit is contained in:
Anna Bodnia
2016-01-18 19:53:53 +02:00
parent f07d78de97
commit 8a4c6560f5
4 changed files with 70 additions and 14 deletions

27
dist/swagger-ui.js vendored
View File

@@ -21089,22 +21089,27 @@ SwaggerUi.partials.signature = (function () {
};
var type = definition.type;
var format = definition.format;
var namespace = getNamespace(definition.xml);
var xml = definition.xml || {};
var namespace = getNamespace(xml);
var attributes = [];
var value;
if (_.keys(primitivesMap).indexOf(type) < 0) { return getErrorMessage(); }
if (namespace) {
attributes.push(namespace);
}
if (_.isArray(definition.enum)){
value = definition.enum[0];
} else {
value = definition.example || primitivesMap[type][format] || primitivesMap[type].default;
}
if (xml.attribute) {
return {name: name, value: value};
}
if (namespace) {
attributes.push(namespace);
}
return wrapTag(name, value, attributes);
};
@@ -21129,9 +21134,19 @@ SwaggerUi.partials.signature = (function () {
properties = properties || {};
serializedProperties = _.map(properties, function (prop, key) {
var xml, result;
if (isParam && prop.readOnly) { return ''; }
return createSchemaXML(key, prop, models);
xml = prop.xml || {};
result = createSchemaXML(key, prop, models);
if (xml.attribute) {
attrs.push(result);
return '';
}
return result;
}).join('');
if (additionalProperties) {

File diff suppressed because one or more lines are too long

View File

@@ -753,22 +753,27 @@ SwaggerUi.partials.signature = (function () {
};
var type = definition.type;
var format = definition.format;
var namespace = getNamespace(definition.xml);
var xml = definition.xml || {};
var namespace = getNamespace(xml);
var attributes = [];
var value;
if (_.keys(primitivesMap).indexOf(type) < 0) { return getErrorMessage(); }
if (namespace) {
attributes.push(namespace);
}
if (_.isArray(definition.enum)){
value = definition.enum[0];
} else {
value = definition.example || primitivesMap[type][format] || primitivesMap[type].default;
}
if (xml.attribute) {
return {name: name, value: value};
}
if (namespace) {
attributes.push(namespace);
}
return wrapTag(name, value, attributes);
};
@@ -793,9 +798,19 @@ SwaggerUi.partials.signature = (function () {
properties = properties || {};
serializedProperties = _.map(properties, function (prop, key) {
var xml, result;
if (isParam && prop.readOnly) { return ''; }
return createSchemaXML(key, prop, models);
xml = prop.xml || {};
result = createSchemaXML(key, prop, models);
if (xml.attribute) {
attrs.push(result);
return '';
}
return result;
}).join('');
if (additionalProperties) {

View File

@@ -442,6 +442,32 @@ describe('SwaggerUi.partials.signature tests', function () {
expect(sut.createSchemaXML(name, definition, models, true)).to.equal(expected);
});
it('returns object with passed parameter as attribute', function () {
var expected = '<animals id="1">' +
'<dog>string</dog>' +
'</animals>';
var name = 'animals';
var definition = {
type: 'object',
properties: {
id: {
type: 'integer',
xml: {
attribute: true
}
},
dog: {
type: 'string'
}
},
xml: {
name: 'animals'
}
};
expect(sut.createSchemaXML(name, definition, models, true)).to.equal(expected);
});
});
describe('schema is in definitions', function () {