json-2-joi 2.3.1 → 2.3.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/CHANGELOG.md +4 -0
- package/lib/resolver.js +19 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/lib/resolver.js
CHANGED
|
@@ -357,10 +357,6 @@ class SchemaResolver {
|
|
|
357
357
|
resolveType(schema, resolveOptions, baseUri) {
|
|
358
358
|
let joischema;
|
|
359
359
|
|
|
360
|
-
const typeDefinitionMap = {
|
|
361
|
-
title: 'label'
|
|
362
|
-
};
|
|
363
|
-
|
|
364
360
|
const joitype = (type, options, format) => {
|
|
365
361
|
let joischema;
|
|
366
362
|
|
|
@@ -397,6 +393,19 @@ class SchemaResolver {
|
|
|
397
393
|
return joischema;
|
|
398
394
|
}
|
|
399
395
|
|
|
396
|
+
let nullIdx;
|
|
397
|
+
if (Array.isArray(schema.type)) {
|
|
398
|
+
nullIdx = schema.type.findIndex((type) => type === 'null');
|
|
399
|
+
if (nullIdx > -1) {
|
|
400
|
+
schema.type.splice(nullIdx, 1);
|
|
401
|
+
}
|
|
402
|
+
if (schema.type.length === 1) {
|
|
403
|
+
schema.type = schema.type[0];
|
|
404
|
+
} else if (schema.type.length === 0) {
|
|
405
|
+
schema.type = 'null';
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
400
409
|
if (Array.isArray(schema.type)) {
|
|
401
410
|
const schemas = [];
|
|
402
411
|
|
|
@@ -408,7 +417,13 @@ class SchemaResolver {
|
|
|
408
417
|
} else {
|
|
409
418
|
joischema = joitype(schema.type, resolveOptions, schema.format);
|
|
410
419
|
}
|
|
420
|
+
if (nullIdx > -1) {
|
|
421
|
+
joischema = joischema.allow(null);
|
|
422
|
+
}
|
|
411
423
|
|
|
424
|
+
const typeDefinitionMap = {
|
|
425
|
+
title: 'label'
|
|
426
|
+
};
|
|
412
427
|
Object.keys(typeDefinitionMap).forEach(function (key) {
|
|
413
428
|
if (schema[key] !== undefined) {
|
|
414
429
|
joischema = joischema[typeDefinitionMap[key]](schema[key]);
|