json-schema-library
Advanced tools
Comparing version 7.4.3 to 7.4.4
@@ -8,2 +8,3 @@ /* eslint quote-props: 0, max-statements-per-line: ["error", { "max": 2 }] */ | ||
import { isJSONError } from "./types"; | ||
import { isEmpty } from "./utils/isEmpty"; | ||
const defaultOptions = { | ||
@@ -123,15 +124,24 @@ addOptionalProps: true, | ||
} | ||
if (schema.oneOf) { | ||
// find correct schema for data | ||
const resolvedSchema = resolveOneOfFuzzy(core, data, schema); | ||
if (isJSONError(resolvedSchema)) { | ||
if (data != null && opts.removeInvalidData !== true) { | ||
return data; | ||
} | ||
// override | ||
schema = schema.oneOf[0]; | ||
data = undefined; | ||
if (Array.isArray(schema.oneOf)) { | ||
if (isEmpty(data)) { | ||
const type = schema.oneOf[0].type || | ||
schema.type || | ||
(schema.const && typeof schema.const) || | ||
getTypeOf(data); | ||
schema = { ...schema.oneOf[0], type }; | ||
} | ||
else { | ||
schema = resolvedSchema; | ||
// find correct schema for data | ||
const resolvedSchema = resolveOneOfFuzzy(core, data, schema); | ||
if (isJSONError(resolvedSchema)) { | ||
if (data != null && opts.removeInvalidData !== true) { | ||
return data; | ||
} | ||
// override | ||
schema = schema.oneOf[0]; | ||
data = undefined; | ||
} | ||
else { | ||
schema = resolvedSchema; | ||
} | ||
} | ||
@@ -138,0 +148,0 @@ } |
@@ -121,3 +121,3 @@ import getTypeOf from "./getTypeOf"; | ||
const dependentProperty = dependentProperties[i]; | ||
const schema = step(core, key, dependencies[dependentProperty], data); | ||
const schema = step(core, key, dependencies[dependentProperty], data, `${pointer}/${dependentProperty}`); | ||
if (!isJSONError(schema)) { | ||
@@ -124,0 +124,0 @@ return schema; |
@@ -9,2 +9,3 @@ /* eslint quote-props: 0, max-statements-per-line: ["error", { "max": 2 }] */ | ||
import { Draft as Core } from "./draft"; | ||
import { isEmpty } from "./utils/isEmpty"; | ||
@@ -161,14 +162,23 @@ export type TemplateOptions = { | ||
if (schema.oneOf) { | ||
// find correct schema for data | ||
const resolvedSchema = resolveOneOfFuzzy(core, data, schema); | ||
if (isJSONError(resolvedSchema)) { | ||
if (data != null && opts.removeInvalidData !== true) { | ||
return data; | ||
if (Array.isArray(schema.oneOf)) { | ||
if (isEmpty(data)) { | ||
const type = | ||
schema.oneOf[0].type || | ||
schema.type || | ||
(schema.const && typeof schema.const) || | ||
getTypeOf(data); | ||
schema = { ...schema.oneOf[0], type }; | ||
} else { | ||
// find correct schema for data | ||
const resolvedSchema = resolveOneOfFuzzy(core, data, schema); | ||
if (isJSONError(resolvedSchema)) { | ||
if (data != null && opts.removeInvalidData !== true) { | ||
return data; | ||
} | ||
// override | ||
schema = schema.oneOf[0]; | ||
data = undefined; | ||
} else { | ||
schema = resolvedSchema; | ||
} | ||
// override | ||
schema = schema.oneOf[0]; | ||
data = undefined; | ||
} else { | ||
schema = resolvedSchema; | ||
} | ||
@@ -175,0 +185,0 @@ } |
@@ -171,3 +171,9 @@ import getTypeOf from "./getTypeOf"; | ||
const dependentProperty = dependentProperties[i]; | ||
const schema = step(core, key, dependencies[dependentProperty], data); | ||
const schema = step( | ||
core, | ||
key, | ||
dependencies[dependentProperty], | ||
data, | ||
`${pointer}/${dependentProperty}` | ||
); | ||
if (!isJSONError(schema)) { | ||
@@ -174,0 +180,0 @@ return schema; |
{ | ||
"name": "json-schema-library", | ||
"version": "7.4.3", | ||
"version": "7.4.4", | ||
"description": "Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation", | ||
@@ -5,0 +5,0 @@ "module": "dist/module/index.js", |
Sorry, the diff of this file is too big to display
446201
192
8513