feat: show type string with minLength 1 as "non-empty"

closes #192
This commit is contained in:
Roman Hotsiy 2017-02-26 00:07:27 +02:00
parent e76bcc3329
commit d175a4d6ae
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
2 changed files with 19 additions and 7 deletions

View File

@ -59,6 +59,16 @@ describe('Spec Helper', () => {
SchemaHelper.runInjectors(schema, schema, '#/'); SchemaHelper.runInjectors(schema, schema, '#/');
schema._range.should.be.equal('5 characters'); schema._range.should.be.equal('5 characters');
}); });
it('should show range as non-empty for minLength == 1', () => {
let schema:any = {
type: 'string',
minLength: 1
};
SchemaHelper.runInjectors(schema, schema, '#/');
schema._range.should.be.equal('non-empty');
});
}); });
}); });

View File

@ -151,19 +151,21 @@ const injectors = {
var range; var range;
if (propertySchema.minLength != undefined && propertySchema.maxLength != undefined) { if (propertySchema.minLength != undefined && propertySchema.maxLength != undefined) {
if (propertySchema.minLength === propertySchema.maxLength) { if (propertySchema.minLength === propertySchema.maxLength) {
range = `${propertySchema.minLength}`; range = `${propertySchema.minLength} characters`;
} else { } else {
range = `[ ${propertySchema.minLength} .. ${propertySchema.maxLength} ]`; range = `[ ${propertySchema.minLength} .. ${propertySchema.maxLength} ] characters`;
} }
} else if (propertySchema.maxLength != undefined) { } else if (propertySchema.maxLength != undefined) {
range = '<= ' + propertySchema.maxLength; range = `<= ${propertySchema.maxLength} characters`;
} else if (propertySchema.minLength != undefined) { } else if (propertySchema.minLength != undefined) {
range = '>= ' + propertySchema.minLength; if (propertySchema.minLength === 1) {
range = 'non-empty';
} else {
range = `>= ${propertySchema.minLength} characters`;
}
} }
if (range) { injectTo._range = range;
injectTo._range = range + ' characters';
}
} }
}, },
file: { file: {