joi-to-json
Advanced tools
Comparing version 2.2.1 to 2.2.2
@@ -160,5 +160,5 @@ /* eslint no-use-before-define: 'off' */ | ||
*/ | ||
if (joiSpec.patterns) { | ||
if (joiSpec.patterns) { | ||
_.each(joiSpec.patterns, patternObj => { | ||
if (typeof patternObj.rule !== 'object') { | ||
if (typeof patternObj.rule !== 'object' || typeof patternObj.regex === 'undefined') { | ||
return | ||
@@ -182,2 +182,10 @@ } | ||
}) | ||
schema.patternProperties = schema.patternProperties || {} | ||
let regexString = patternObj.regex | ||
regexString = regexString.indexOf('/') === 0 ? regexString.substring(1) : regexString | ||
regexString = regexString.lastIndexOf('/') > -1 ? regexString.substring(0, regexString.length - 1) : regexString | ||
schema.patternProperties[regexString] = schema.properties[patternObj.regex] | ||
}) | ||
@@ -184,0 +192,0 @@ } |
{ | ||
"name": "joi-to-json", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "joi to JSON / OpenAPI Schema Converter", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,3 +5,3 @@ # joi-to-json | ||
I have been using [joi](https://hapi.dev/family/joi/) a lot in different Node.js projects which guards the API. | ||
I have been using [joi](https://joi.dev/) a lot in different Node.js projects to guard the API. | ||
It's **The most powerful schema description language and data validator for JavaScript.** as it said. | ||
@@ -107,4 +107,8 @@ | ||
## Known Limitation | ||
* For `object.pattern` usage in Joi, `pattern` parameter can only be a regular expression now as I cannot convert Joi object to regex yet. | ||
## License | ||
MIT |
29604
791
113