1
0
Fork 0

Swagger models should reflect required properties.

This commit is contained in:
Alan Plum 2014-11-18 11:21:08 +01:00
parent 53fbc02890
commit 74f7d0ee5e
1 changed files with 5 additions and 4 deletions

View File

@ -161,25 +161,26 @@ _.extend(Model, {
if (this.prototype.schema) {
_.each(this.prototype.schema, function (schema, attributeName) {
var description = schema.describe(),
type = description.type,
jsonSchema = {type: description.type},
rules = description.rules,
flags = description.flags;
if (flags && flags.presence === 'required') {
jsonSchema.required = true;
required.push(attributeName);
}
if (
type === 'number' &&
jsonSchema.type === 'number' &&
_.isArray(rules) &&
_.some(rules, function (rule) {
return rule.name === 'integer';
})
) {
type = 'integer';
jsonSchema.type = 'integer';
}
properties[attributeName] = {type: type};
properties[attributeName] = jsonSchema;
});
} else {
// deprecated