joi-to-json 2.3.3 → 2.3.4
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/lib/parsers/json.js +9 -1
- package/lib/parsers/open-api.js +4 -0
- package/package.json +1 -1
package/lib/parsers/json.js
CHANGED
|
@@ -115,9 +115,16 @@ class JoiJsonSchemaParser {
|
|
|
115
115
|
return _.get(fieldDefn, 'flags.default')
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
_getConst(fieldDefn) {
|
|
119
|
+
const enumList = fieldDefn[this.enumFieldName]
|
|
120
|
+
if (fieldDefn.flags && fieldDefn.flags.only && enumList.length === 1) {
|
|
121
|
+
return enumList[0]
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
118
125
|
_getEnum(fieldDefn) {
|
|
119
126
|
const enumList = fieldDefn[this.enumFieldName]
|
|
120
|
-
if (fieldDefn.flags && fieldDefn.flags.only &&
|
|
127
|
+
if (fieldDefn.flags && fieldDefn.flags.only && enumList.length > 1) {
|
|
121
128
|
return _.uniq(enumList)
|
|
122
129
|
}
|
|
123
130
|
}
|
|
@@ -141,6 +148,7 @@ class JoiJsonSchemaParser {
|
|
|
141
148
|
this._setIfNotEmpty(fieldSchema, 'examples', this._getFieldExample(fieldDefn))
|
|
142
149
|
this._setIfNotEmpty(fieldSchema, 'description', this._getFieldDescription(fieldDefn))
|
|
143
150
|
this._setIfNotEmpty(fieldSchema, 'default', this._getDefaultValue(fieldDefn))
|
|
151
|
+
this._setIfNotEmpty(fieldSchema, 'const', this._getConst(fieldDefn))
|
|
144
152
|
this._setIfNotEmpty(fieldSchema, 'enum', this._getEnum(fieldDefn))
|
|
145
153
|
}
|
|
146
154
|
|
package/lib/parsers/open-api.js
CHANGED