joi-to-json 2.2.2 → 2.2.3

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.
@@ -106,6 +106,14 @@ class JoiJsonSchemaParser {
106
106
  return _.isEmpty(enumList) ? undefined : enumList
107
107
  }
108
108
 
109
+ _getUnknown(joiSpec) {
110
+ let allowUnknown = _.get(joiSpec, `${this.optionsFieldName}.allowUnknown`, false)
111
+ if (joiSpec.flags && typeof joiSpec.flags[this.allowUnknownFlagName] !== 'undefined') {
112
+ allowUnknown = joiSpec.flags[this.allowUnknownFlagName]
113
+ }
114
+ return allowUnknown
115
+ }
116
+
109
117
  _setIfNotEmpty(schema, field, value) {
110
118
  if (value !== null && value !== undefined) {
111
119
  schema[field] = value
@@ -139,10 +147,7 @@ class JoiJsonSchemaParser {
139
147
  schema.properties = {}
140
148
  schema.required = []
141
149
 
142
- schema.additionalProperties = _.get(joiSpec, `${this.optionsFieldName}.allowUnknown`, false)
143
- if (joiSpec.flags && typeof joiSpec.flags[this.allowUnknownFlagName] !== 'undefined') {
144
- schema.additionalProperties = joiSpec.flags[this.allowUnknownFlagName]
145
- }
150
+ schema.additionalProperties = this._getUnknown(joiSpec)
146
151
 
147
152
  _.map(joiSpec[this.childrenFieldName], (fieldDefn, key) => {
148
153
  const fieldSchema = this.parse(fieldDefn)
@@ -170,6 +175,7 @@ class JoiJsonSchemaParser {
170
175
  schema.properties[patternObj.regex].required = []
171
176
 
172
177
  const childKeys = patternObj.rule.keys || patternObj.rule.children
178
+ schema.properties[patternObj.regex].additionalProperties = this._getUnknown(patternObj.rule)
173
179
 
174
180
  _.each(childKeys, (ruleObj, key) => {
175
181
  schema.properties[patternObj.regex].properties[key] = this.parse(ruleObj)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joi-to-json",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "joi to JSON / OpenAPI Schema Converter",
5
5
  "main": "index.js",
6
6
  "repository": {