joi-to-json 2.3.0 → 2.3.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.
- package/index.js +2 -2
- package/lib/parsers/json.js +4 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -21,7 +21,7 @@ fs.readdirSync(parsersDir).forEach(file => {
|
|
|
21
21
|
}
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
-
function parse(joiObj, type = 'json') {
|
|
24
|
+
function parse(joiObj, type = 'json', definitions = {}) {
|
|
25
25
|
if (typeof joiObj.describe !== 'function') {
|
|
26
26
|
throw new Error('Not an joi object.')
|
|
27
27
|
}
|
|
@@ -58,7 +58,7 @@ function parse(joiObj, type = 'json') {
|
|
|
58
58
|
throw new Error(`No parser is registered for ${type}`)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
return new parser().parse(joiBaseSpec)
|
|
61
|
+
return new parser().parse(joiBaseSpec, definitions)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
module.exports = parse
|
package/lib/parsers/json.js
CHANGED
|
@@ -31,6 +31,10 @@ class JoiJsonSchemaParser {
|
|
|
31
31
|
this._setMetaProperties(schema, joiSpec)
|
|
32
32
|
this._setLinkFieldProperties(schema, joiSpec)
|
|
33
33
|
|
|
34
|
+
if (!_.isEmpty(joiSpec.shared)) {
|
|
35
|
+
this.parse(joiSpec.shared[0], definitions, level)
|
|
36
|
+
}
|
|
37
|
+
|
|
34
38
|
const schemaId = _.get(joiSpec, 'flags.id')
|
|
35
39
|
if (schemaId) {
|
|
36
40
|
definitions[schemaId] = schema
|