joi-to-json
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -0,3 +1,7 @@ | ||
### 3.1.0 | ||
- Add support for relation operator `with` and `without`. | ||
### 3.0.0 | ||
- [BREAKING] Default enable feature: relation operator `and`, `or`, `nand`, `xor`, `oxor`. |
@@ -0,0 +0,0 @@ const cmp = require('semver-compare') |
@@ -0,0 +0,0 @@ const _ = require('lodash') |
@@ -6,3 +6,12 @@ const _ = require('lodash') | ||
constructor(opts = {}) { | ||
super(_.merge({ logicalOpParser: { xor: null } }, opts)) | ||
super(_.merge({ | ||
logicalOpParser: { | ||
xor: null, | ||
with: function (schema, dependency) { | ||
schema.dependencies = schema.dependencies || {} | ||
schema.dependencies[dependency.key] = dependency.peers | ||
}, | ||
without: null | ||
} | ||
}, opts)) | ||
} | ||
@@ -9,0 +18,0 @@ |
@@ -48,2 +48,16 @@ /* eslint no-use-before-define: 'off' */ | ||
}) | ||
}, | ||
with: function (schema, dependency) { | ||
schema.dependentRequired = schema.dependentRequired || {} | ||
schema.dependentRequired[dependency.key] = dependency.peers | ||
}, | ||
without: function (schema, dependency) { | ||
schema.if = { required: [dependency.key] } | ||
schema.then = { | ||
not: { | ||
anyOf: _.map(dependency.peers, (peer) => { | ||
return { required: [peer] } | ||
}) | ||
} | ||
} | ||
} | ||
@@ -310,2 +324,6 @@ } | ||
} else { | ||
const withDependencies = _.remove(joiSpec.dependencies, (dependency) => { | ||
return dependency.rel === 'with' | ||
}) | ||
schema.allOf = _.compact(_.map(joiSpec.dependencies, (dependency) => { | ||
@@ -318,2 +336,7 @@ const subSchema = this._setDependencySubSchema({}, dependency) | ||
})) | ||
_.each(withDependencies, (dependency) => { | ||
this._setDependencySubSchema(schema, dependency) | ||
}) | ||
if (schema.allOf.length === 0) { | ||
@@ -320,0 +343,0 @@ // When the logicalOpParser is set to false |
@@ -5,2 +5,11 @@ const _ = require('lodash') | ||
class JoiOpenApiSchemaParser extends JoiJsonSchemaParser { | ||
constructor(opts = {}) { | ||
super(_.merge({ | ||
logicalOpParser: { | ||
xor: null, | ||
with: null | ||
} | ||
}, opts)) | ||
} | ||
parse(joiSpec, definitions = {}, level = 0) { | ||
@@ -7,0 +16,0 @@ const fullSchema = super.parse(joiSpec, definitions, level) |
{ | ||
"name": "joi-to-json", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "joi to JSON / OpenAPI Schema Converter", | ||
@@ -44,2 +44,3 @@ "main": "index.js", | ||
"files": [ | ||
"docs/**/*", | ||
"lib/**/*.js", | ||
@@ -46,0 +47,0 @@ "index.js", |
47843
17
1016