joi-to-json
Advanced tools
Comparing version 4.0.1 to 4.1.0
@@ -0,0 +0,0 @@ const _ = require('lodash') |
@@ -0,0 +0,0 @@ const BaseConverter = require('./v15') |
@@ -7,2 +7,3 @@ const _ = require('lodash') | ||
super(_.merge({ | ||
$schema: 'http://json-schema.org/draft-04/schema#', | ||
logicalOpParser: { | ||
@@ -26,2 +27,11 @@ xor: null, | ||
if (typeof fieldSchema.exclusiveMinimum !== 'undefined') { | ||
fieldSchema.minimum = fieldSchema.exclusiveMinimum | ||
fieldSchema.exclusiveMinimum = true | ||
} | ||
if (typeof fieldSchema.exclusiveMaximum !== 'undefined') { | ||
fieldSchema.maximum = fieldSchema.exclusiveMaximum | ||
fieldSchema.exclusiveMaximum = true | ||
} | ||
if (typeof fieldSchema.minimum !== 'undefined' && fieldSchema.minimum === fieldSchema.exclusiveMinimum) { | ||
@@ -28,0 +38,0 @@ fieldSchema.exclusiveMinimum = true |
@@ -5,2 +5,8 @@ const _ = require('lodash') | ||
class JoiJsonDraftSchemaParser extends JoiJsonSchemaParser { | ||
constructor(opts = {}) { | ||
super(_.merge({ | ||
$schema: 'https://json-schema.org/draft/2019-09/schema' | ||
}, opts)) | ||
} | ||
parse(joiSpec, definitions = {}, level = 0) { | ||
@@ -7,0 +13,0 @@ const schema = super.parse(joiSpec, definitions, level) |
@@ -85,2 +85,4 @@ /* eslint no-use-before-define: 'off' */ | ||
constructor(opts = {}) { | ||
this.$schema = opts.$schema || 'http://json-schema.org/draft-07/schema#' | ||
this.includeSchemaDialect = opts.includeSchemaDialect || false | ||
this.childrenFieldName = this._getChildrenFieldName() | ||
@@ -137,2 +139,6 @@ this.optionsFieldName = this._getOptionsFieldName() | ||
if (this.includeSchemaDialect && level === 0 && this.$schema) { | ||
schema.$schema = this.$schema | ||
} | ||
return schema | ||
@@ -400,2 +406,9 @@ } | ||
break | ||
case 'sign': | ||
if (rule.args.sign === 'positive') { | ||
fieldSchema.exclusiveMinimum = 0 | ||
} else if (rule.args.sign === 'negative') { | ||
fieldSchema.exclusiveMaximum = 0 | ||
} | ||
break | ||
default: | ||
@@ -402,0 +415,0 @@ break |
@@ -13,2 +13,4 @@ const _ = require('lodash') | ||
}, opts)) | ||
this.$schema = undefined | ||
} | ||
@@ -15,0 +17,0 @@ |
{ | ||
"name": "joi-to-json", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"description": "joi to JSON / OpenAPI Schema Converter", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
61964
1319