joi-to-json 2.3.2 → 2.3.5
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 +15 -7
- package/lib/parsers/open-api.js +4 -0
- package/package.json +1 -1
package/lib/parsers/json.js
CHANGED
|
@@ -29,7 +29,11 @@ class JoiJsonSchemaParser {
|
|
|
29
29
|
this._setAnyProperties(schema, joiSpec, definitions, level)
|
|
30
30
|
this._addNullTypeIfNullable(schema, joiSpec)
|
|
31
31
|
this._setMetaProperties(schema, joiSpec)
|
|
32
|
-
this._setLinkFieldProperties(schema, joiSpec
|
|
32
|
+
this._setLinkFieldProperties(schema, joiSpec)
|
|
33
|
+
|
|
34
|
+
if (!_.isEmpty(joiSpec.shared)) {
|
|
35
|
+
this.parse(joiSpec.shared[0], definitions, level)
|
|
36
|
+
}
|
|
33
37
|
|
|
34
38
|
const schemaId = _.get(joiSpec, 'flags.id')
|
|
35
39
|
if (schemaId) {
|
|
@@ -111,9 +115,16 @@ class JoiJsonSchemaParser {
|
|
|
111
115
|
return _.get(fieldDefn, 'flags.default')
|
|
112
116
|
}
|
|
113
117
|
|
|
118
|
+
_getConst(fieldDefn) {
|
|
119
|
+
const enumList = fieldDefn[this.enumFieldName]
|
|
120
|
+
if (fieldDefn.flags && fieldDefn.flags.only && _.size(enumList) === 1) {
|
|
121
|
+
return enumList[0]
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
114
125
|
_getEnum(fieldDefn) {
|
|
115
126
|
const enumList = fieldDefn[this.enumFieldName]
|
|
116
|
-
if (fieldDefn.flags && fieldDefn.flags.only &&
|
|
127
|
+
if (fieldDefn.flags && fieldDefn.flags.only && _.size(enumList) > 1) {
|
|
117
128
|
return _.uniq(enumList)
|
|
118
129
|
}
|
|
119
130
|
}
|
|
@@ -137,6 +148,7 @@ class JoiJsonSchemaParser {
|
|
|
137
148
|
this._setIfNotEmpty(fieldSchema, 'examples', this._getFieldExample(fieldDefn))
|
|
138
149
|
this._setIfNotEmpty(fieldSchema, 'description', this._getFieldDescription(fieldDefn))
|
|
139
150
|
this._setIfNotEmpty(fieldSchema, 'default', this._getDefaultValue(fieldDefn))
|
|
151
|
+
this._setIfNotEmpty(fieldSchema, 'const', this._getConst(fieldDefn))
|
|
140
152
|
this._setIfNotEmpty(fieldSchema, 'enum', this._getEnum(fieldDefn))
|
|
141
153
|
}
|
|
142
154
|
|
|
@@ -441,7 +453,7 @@ class JoiJsonSchemaParser {
|
|
|
441
453
|
})
|
|
442
454
|
}
|
|
443
455
|
|
|
444
|
-
_setLinkFieldProperties(schema, joiSpec
|
|
456
|
+
_setLinkFieldProperties(schema, joiSpec) {
|
|
445
457
|
if (schema.type !== 'link') {
|
|
446
458
|
return
|
|
447
459
|
}
|
|
@@ -450,10 +462,6 @@ class JoiJsonSchemaParser {
|
|
|
450
462
|
schema.$ref = `${this._getLocalSchemaBasePath()}/${joiSpec.link.ref.path.join('/')}`
|
|
451
463
|
delete schema.type
|
|
452
464
|
}
|
|
453
|
-
|
|
454
|
-
if (!_.isEmpty(joiSpec.shared)) {
|
|
455
|
-
this.parse(joiSpec.shared[0], definitions, level)
|
|
456
|
-
}
|
|
457
465
|
}
|
|
458
466
|
}
|
|
459
467
|
|
package/lib/parsers/open-api.js
CHANGED