Skip to content

Commit

Permalink
#40: added validation for scale and precision
Browse files Browse the repository at this point in the history
  • Loading branch information
mohit-s96 committed Aug 7, 2023
1 parent 532e990 commit 9004bc2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/schema/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ function createDefinitions(resources, lookups, additionalProperties = false) {
if (field.maxLength) itemTypeSchema['maxLength'] = field.maxLength;
if (field.type === EDM_DATE_TIME_OFFSET) itemTypeSchema['format'] = 'date-time';
if (field.type === EDM_DATE) itemTypeSchema['format'] = 'date';
if (mappedType === 'integer' || mappedType === 'number') {
if (field.scale) itemTypeSchema['multipleOf'] = 1 / 10 ** field.scale;
if (field.precision) itemTypeSchema['maximum'] = Number('9'.repeat(field.precision));
}

if (!isSimpleType(field.type)) {
const possibleValues = getPossibleLookupValues(field.type);
Expand Down Expand Up @@ -80,6 +84,10 @@ function createDefinitions(resources, lookups, additionalProperties = false) {
if (field.maxLength) schema['maxLength'] = field.maxLength;
if (field.type === EDM_DATE_TIME_OFFSET) schema['format'] = 'date-time';
if (field.type === EDM_DATE) schema['format'] = 'date';
if (fieldType === 'integer' || fieldType === 'number') {
if (field.scale) schema['multipleOf'] = 1 / 10 ** field.scale;
if (field.precision) schema['maximum'] = Number('9'.repeat(field.precision));
}

if (!isSimpleType(field.type)) {
const possibleValues = getPossibleLookupValues(field.type);
Expand Down

0 comments on commit 9004bc2

Please sign in to comment.