Skip to content

Commit

Permalink
dist: update
Browse files Browse the repository at this point in the history
  • Loading branch information
sagold committed Dec 1, 2024
1 parent e90675f commit c334190
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/jsonSchemaLibrary.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/getChildSchemaSelection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { JsonError, JsonSchema } from "./types";
* could be added at the given property (e.g. item-index), thus an array of options is returned. In all other cases
* a list with a single item will be returned
*
* @param draft - draft to use
* @param draft - draft to use
* @param property - parent schema of following property
* @param [schema] - parent schema of following property
* @return
Expand Down
1 change: 1 addition & 0 deletions dist/lib/resolveDynamicSchema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export declare function isDynamicSchema(schema: JsonData): boolean;
/**
* @note this utility does not reference draft methods for resolution
* @todo consider using draft methods
* @todo consider exposing separate info-object (oneOf-Index)
*
* Resolves all dynamic schema definitions for the given input data and returns
* the resulting json-schema without any dynamic schema definitions. The result
Expand Down
9 changes: 8 additions & 1 deletion dist/module/lib/features/if.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,35 @@ export function resolveIfSchema(node, data) {
return undefined;
}
if (node.schema.if === false) {
// @evaluation-info
// schema.__ifelse = true
return node.next(node.schema.else);
}
if (node.schema.if && (node.schema.then || node.schema.else)) {
const ifNode = node.draft.resolveRef(node.next(node.schema.if));
const ifErrors = node.draft.validate(ifNode, data);
if (ifErrors.length === 0 && node.schema.then) {
const thenNode = node.next(node.schema.then);
// @evaluation-info
// schema.__ifthen = true
return node.draft.resolveRef(thenNode);
}
if (ifErrors.length !== 0 && node.schema.else) {
const elseNode = node.next(node.schema.else);
// @evaluation-info
// schema.__ifelse = true
return node.draft.resolveRef(elseNode);
}
}
return undefined;
}
/**
* @returns validation result of it-then-else schema
*/
const validateIf = (node, value) => {
const resolvedNode = resolveIfSchema(node, value);
if (resolvedNode) {
// @recursiveRef ok, we not just add per pointer, but any evlauation to dynamic scope / validation path
// @recursiveRef ok, we not just add per pointer, but any evluation to dynamic scope / validation path
return node.draft.validate(resolvedNode, value);
}
};
Expand Down
15 changes: 15 additions & 0 deletions dist/module/lib/features/oneOf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { errorOrPromise } from "../utils/filter";
import { isJsonError } from "../types";
import { isObject } from "../utils/isObject";
const { DECLARATOR_ONEOF } = settings;
function setOneOfOrigin(schema, index) {
if (isObject(schema)) {
schema.__oneOfIndex = index;
}
}
/**
* Selects and returns a oneOf schema for the given data
*
Expand Down Expand Up @@ -48,6 +53,8 @@ export function resolveOneOf(node, data) {
errors.push(...result);
}
else {
// @evaluation-info
setOneOfOrigin(oneNode.schema, i);
return resultNode.next(oneNode.schema);
}
}
Expand All @@ -73,6 +80,8 @@ export function resolveOneOf(node, data) {
}
}
if (matches.length === 1) {
// @evaluation-info
setOneOfOrigin(matches[0].schema, matches[0].index);
return node.next(matches[0].schema);
}
if (matches.length > 1) {
Expand Down Expand Up @@ -162,6 +171,8 @@ export function resolveOneOfFuzzy(node, data) {
errors.push(...result);
}
else {
// @evaluation-info
setOneOfOrigin(oneNode.schema, i);
return resultNode.next(oneNode.schema);
}
}
Expand All @@ -183,6 +194,8 @@ export function resolveOneOfFuzzy(node, data) {
}
}
if (matches.length === 1) {
// @evaluation-info
setOneOfOrigin(matches[0].schema, matches[0].index);
return node.next(matches[0].schema);
}
// fuzzy match oneOf
Expand All @@ -207,6 +220,8 @@ export function resolveOneOfFuzzy(node, data) {
oneOf: schema.oneOf
});
}
// @evaluation-info
setOneOfOrigin(schemaOfItem, schemaOfIndex);
return node.next(schemaOfItem);
}
if (matches.length > 1) {
Expand Down
8 changes: 6 additions & 2 deletions dist/module/lib/getChildSchemaSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isJsonError } from "./types";
* could be added at the given property (e.g. item-index), thus an array of options is returned. In all other cases
* a list with a single item will be returned
*
* @param draft - draft to use
* @param draft - draft to use
* @param property - parent schema of following property
* @param [schema] - parent schema of following property
* @return
Expand All @@ -17,9 +17,13 @@ export default function getChildSchemaSelection(draft, property, schema = draft.
if ((_a = schema.items) === null || _a === void 0 ? void 0 : _a.oneOf) {
return schema.items.oneOf.map((item) => draft.createNode(item).resolveRef().schema);
}
if (Array.isArray(schema.items) && schema.items.length <= +property) {
return [];
}
const node = draft.step(draft.createNode(schema), property, {});
if (isJsonError(node)) {
return node;
const error = node;
return error;
}
return [node.schema];
}
1 change: 1 addition & 0 deletions dist/module/lib/resolveDynamicSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function isDynamicSchema(schema) {
/**
* @note this utility does not reference draft methods for resolution
* @todo consider using draft methods
* @todo consider exposing separate info-object (oneOf-Index)
*
* Resolves all dynamic schema definitions for the given input data and returns
* the resulting json-schema without any dynamic schema definitions. The result
Expand Down

0 comments on commit c334190

Please sign in to comment.