joi-to-json 2.2.1 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Objective
4
4
 
5
- I have been using [joi](https://hapi.dev/family/joi/) a lot in different Node.js projects which guards the API.
5
+ I have been using [joi](https://joi.dev/) a lot in different Node.js projects to guard the API.
6
6
  It's **The most powerful schema description language and data validator for JavaScript.** as it said.
7
7
 
8
8
  Many times, we need to utilize this schema description to produce other output, such as Swagger OpenAPI doc.
@@ -103,6 +103,10 @@ You can optionally set below environment variables:
103
103
 
104
104
  * `CASE_PATTERN=joi-obj-12` to control which version of joi obj to test
105
105
 
106
+ ## Known Limitation
107
+
108
+ * For `object.pattern` usage in Joi, `pattern` parameter can only be a regular expression now as I cannot convert Joi object to regex yet.
109
+
106
110
  ## License
107
111
 
108
112
  MIT
@@ -157,9 +157,9 @@ class JoiJsonSchemaParser {
157
157
  * For dynamic key scenarios to store the pattern as key
158
158
  * and have the properties be as with other examples
159
159
  */
160
- if (joiSpec.patterns) {
160
+ if (joiSpec.patterns) {
161
161
  _.each(joiSpec.patterns, patternObj => {
162
- if (typeof patternObj.rule !== 'object') {
162
+ if (typeof patternObj.rule !== 'object' || typeof patternObj.regex === 'undefined') {
163
163
  return
164
164
  }
165
165
 
@@ -178,6 +178,14 @@ class JoiJsonSchemaParser {
178
178
  schema.properties[patternObj.regex].required.push(key)
179
179
  }
180
180
  })
181
+
182
+ schema.patternProperties = schema.patternProperties || {}
183
+
184
+ let regexString = patternObj.regex
185
+ regexString = regexString.indexOf('/') === 0 ? regexString.substring(1) : regexString
186
+ regexString = regexString.lastIndexOf('/') > -1 ? regexString.substring(0, regexString.length - 1) : regexString
187
+
188
+ schema.patternProperties[regexString] = schema.properties[patternObj.regex]
181
189
  })
182
190
  }
183
191
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joi-to-json",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "joi to JSON / OpenAPI Schema Converter",
5
5
  "main": "index.js",
6
6
  "repository": {