Skip to content

Commit

Permalink
feat: show type string with minLength 1 as "non-empty"
Browse files Browse the repository at this point in the history
closes #192
  • Loading branch information
RomanHotsiy committed Feb 25, 2017
1 parent e76bcc3 commit d175a4d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
10 changes: 10 additions & 0 deletions lib/services/schema-helper.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ describe('Spec Helper', () => {
SchemaHelper.runInjectors(schema, schema, '#/');
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');
});
});
});

Expand Down
16 changes: 9 additions & 7 deletions lib/services/schema-helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,21 @@ const injectors = {
var range;
if (propertySchema.minLength != undefined && propertySchema.maxLength != undefined) {
if (propertySchema.minLength === propertySchema.maxLength) {
range = `${propertySchema.minLength}`;
range = `${propertySchema.minLength} characters`;
} else {
range = `[ ${propertySchema.minLength} .. ${propertySchema.maxLength} ]`;
range = `[ ${propertySchema.minLength} .. ${propertySchema.maxLength} ] characters`;
}
} else if (propertySchema.maxLength != undefined) {
range = '<= ' + propertySchema.maxLength;
range = `<= ${propertySchema.maxLength} characters`;
} 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 + ' characters';
}
injectTo._range = range;
}
},
file: {
Expand Down

0 comments on commit d175a4d

Please sign in to comment.