joi-to-json
Advanced tools
Comparing version 2.2.0 to 2.2.1
@@ -54,2 +54,3 @@ const cmp = require('semver-compare') | ||
const joiBaseSpec = new convertor().toBaseSpec(joiObj.describe()) | ||
// fs.writeFileSync(`./internal_${convertor.getSupportVersion()}_${type}.json`, JSON.stringify(joiBaseSpec, null, 2)) | ||
const parser = parsers[type] | ||
@@ -56,0 +57,0 @@ if (!parser) { |
@@ -40,3 +40,9 @@ const _ = require('lodash') | ||
_convertAlternatives(joiObj) { | ||
if (joiObj.base && joiObj.base.type === 'any') { | ||
let isWhenCase = false | ||
if (joiObj.alternatives.length === 1) { | ||
const condition = joiObj.alternatives[0] | ||
isWhenCase = !!condition.then || !!condition.otherwise | ||
} | ||
if (isWhenCase) { | ||
// when case | ||
@@ -43,0 +49,0 @@ joiObj.type = 'any' |
@@ -357,6 +357,13 @@ /* eslint no-use-before-define: 'off' */ | ||
if (joiSpec.matches.length === 1 && joiSpec.matches[0].switch) { | ||
schema.oneOf = _.map(joiSpec.matches[0].switch, (condition) => { | ||
return this.parse(condition.then || condition.otherwise) | ||
}) | ||
if (joiSpec.matches.length === 1) { | ||
const match = joiSpec.matches[0] | ||
if (match.switch) { | ||
schema.oneOf = _.map(match.switch, (condition) => { | ||
return this.parse(condition.then || condition.otherwise) | ||
}) | ||
} else if (match.then || match.otherwise) { | ||
schema.oneOf = [] | ||
if (match.then) schema.oneOf.push(this.parse(match.then)) | ||
if (match.otherwise) schema.oneOf.push(this.parse(match.otherwise)) | ||
} | ||
} else { | ||
@@ -363,0 +370,0 @@ schema.oneOf = _.map(joiSpec.matches, (match) => { |
{ | ||
"name": "joi-to-json", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "joi to JSON / OpenAPI Schema Converter", | ||
@@ -30,6 +30,6 @@ "main": "index.js", | ||
"devDependencies": { | ||
"ajv": "^8.6.3", | ||
"ajv": "^8.11.0", | ||
"ajv-draft-04": "^1.0.0", | ||
"eslint": "^7.32.0", | ||
"jest": "^27.2.0", | ||
"eslint": "^8.12.0", | ||
"jest": "^27.5.1", | ||
"joi-12": "npm:@commercial/joi@^12.1.0", | ||
@@ -36,0 +36,0 @@ "joi-13": "npm:joi@^13.7.0", |
29006
786