diff --git a/lib/types/number.js b/lib/types/number.js index b79c1299..ae07eae8 100755 --- a/lib/types/number.js +++ b/lib/types/number.js @@ -269,6 +269,13 @@ module.exports = Any.extend({ } return helpers.error('number.port'); + }, + jsonSchema(rule, res) { + + res.type = 'integer'; + res.minimum = 0; + res.maximum = 65535; + return res; } }, @@ -318,7 +325,13 @@ module.exports = Any.extend({ }, jsonSchema(rule, res) { - res['x-constraint'] = { ...res['x-constraint'], sign: rule.args.sign }; + if (rule.args.sign === 'positive') { + res.exclusiveMinimum = 0; + } + else { + res.exclusiveMaximum = 0; + } + return res; } }, diff --git a/test/json-schema.js b/test/json-schema.js index d84ffab9..b09db475 100644 --- a/test/json-schema.js +++ b/test/json-schema.js @@ -1070,39 +1070,38 @@ describe('jsonSchema', () => { Helper.validateJsonSchema(Joi.number().positive(), { type: 'number', - 'x-constraint': { - sign: 'positive' - } + exclusiveMinimum: 0 }); Helper.validateJsonSchema(Joi.number().positive().only(), { type: 'number', - 'x-constraint': { - sign: 'positive' - } + exclusiveMinimum: 0 }); Helper.validateJsonSchema(Joi.number().negative(), { type: 'number', - 'x-constraint': { - sign: 'negative' - } + exclusiveMaximum: 0 }); Helper.validateJsonSchema(Joi.number().positive().multiple(3), { type: 'number', multipleOf: 3, - 'x-constraint': { - sign: 'positive' - } + exclusiveMinimum: 0 }); Helper.validateJsonSchema(Joi.number().multiple(3).positive(), { type: 'number', multipleOf: 3, - 'x-constraint': { - sign: 'positive' - } + exclusiveMinimum: 0 + }); + }); + + it('represents number.port() constraints', () => { + + Helper.validateJsonSchema(Joi.number().port(), { + type: 'integer', + minimum: 0, + maximum: 65535 }); });