json-schema-library 11.0.4 → 11.1.0
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 +11 -0
- package/README.md +112 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +93 -16
- package/dist/index.d.mts +93 -16
- package/dist/index.mjs +1 -1
- package/dist/jlib.js +3 -3
- package/index.ts +10 -1
- package/package.json +11 -8
- package/src/Draft.ts +1 -1
- package/src/Keyword.ts +36 -10
- package/src/SchemaNode.ts +75 -16
- package/src/compileSchema.ts +53 -4
- package/src/errors/errors.ts +4 -1
- package/src/keywords/$defs.ts +34 -8
- package/src/keywords/$ref.ts +12 -0
- package/src/keywords/additionalProperties.ts +19 -8
- package/src/keywords/allOf.ts +44 -18
- package/src/keywords/anyOf.ts +38 -19
- package/src/keywords/contains.ts +21 -9
- package/src/keywords/dependencies.ts +37 -17
- package/src/keywords/dependentRequired.ts +56 -38
- package/src/keywords/dependentSchemas.ts +37 -13
- package/src/keywords/deprecated.ts +32 -8
- package/src/keywords/enum.ts +30 -8
- package/src/keywords/exclusiveMaximum.ts +21 -2
- package/src/keywords/exclusiveMinimum.ts +22 -3
- package/src/keywords/format.ts +21 -2
- package/src/keywords/ifthenelse.ts +49 -5
- package/src/keywords/items.ts +27 -13
- package/src/keywords/maxItems.ts +22 -2
- package/src/keywords/maxLength.ts +30 -9
- package/src/keywords/maxProperties.ts +30 -9
- package/src/keywords/maximum.ts +28 -8
- package/src/keywords/minItems.ts +30 -9
- package/src/keywords/minLength.ts +30 -9
- package/src/keywords/minProperties.ts +26 -5
- package/src/keywords/minimum.ts +32 -13
- package/src/keywords/multipleOf.ts +33 -12
- package/src/keywords/not.ts +23 -10
- package/src/keywords/oneOf.ts +29 -9
- package/src/keywords/pattern.ts +35 -9
- package/src/keywords/properties.ts +35 -12
- package/src/keywords/propertyDependencies.test.ts +180 -0
- package/src/keywords/propertyDependencies.ts +173 -0
- package/src/keywords/propertyNames.ts +26 -14
- package/src/keywords/required.ts +31 -8
- package/src/keywords/type.ts +53 -16
- package/src/keywords/unevaluatedItems.ts +24 -8
- package/src/keywords/unevaluatedProperties.ts +24 -7
- package/src/keywords/uniqueItems.ts +23 -4
- package/src/mergeNode.ts +9 -4
- package/src/settings.ts +2 -1
- package/src/types.ts +1 -1
- package/src/utils/isListOfStrings.ts +3 -0
- package/src/validate.test.ts +0 -2
- package/src/validateNode.ts +2 -2
- package/src/validateSchema.test.ts +312 -0
package/dist/index.d.cts
CHANGED
|
@@ -29,27 +29,51 @@ type Maybe<T> = T | undefined;
|
|
|
29
29
|
type ValidationAnnotation = JsonError | JsonAnnotation | Promise<Maybe<ValidationAnnotation>[]>;
|
|
30
30
|
type ValidationResult = Maybe<ValidationAnnotation>;
|
|
31
31
|
type ValidationReturnType = ValidationResult | ValidationResult[];
|
|
32
|
-
type
|
|
32
|
+
type SchemaNodeWithRequired<K extends keyof SchemaNode> = SchemaNode & Required<Pick<SchemaNode, K>>;
|
|
33
|
+
type JsonSchemaValidatorParams<Key extends keyof SchemaNode = keyof SchemaNode> = {
|
|
33
34
|
pointer: string;
|
|
34
35
|
data: unknown;
|
|
35
|
-
node:
|
|
36
|
+
node: SchemaNodeWithRequired<Key>;
|
|
36
37
|
path: ValidationPath;
|
|
37
38
|
};
|
|
38
|
-
interface JsonSchemaValidator {
|
|
39
|
+
interface JsonSchemaValidator<Key extends keyof SchemaNode = keyof SchemaNode> {
|
|
39
40
|
toJSON?: () => string;
|
|
40
41
|
order?: number;
|
|
41
|
-
(options: JsonSchemaValidatorParams): ValidationReturnType;
|
|
42
|
+
(options: JsonSchemaValidatorParams<Key>): ValidationReturnType;
|
|
42
43
|
}
|
|
43
|
-
type Keyword = {
|
|
44
|
+
type Keyword<Key extends keyof SchemaNode = keyof SchemaNode> = {
|
|
44
45
|
id: string; /** unique keyword corresponding to JSON Schema keywords (or custom) */
|
|
45
46
|
keyword: string; /** sort order of keyword. Lower numbers will be processed last. Default is 0 */
|
|
46
|
-
order?: number;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
order?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Called once for each JSON Schema dduring compileSchema to evaluate keyword.
|
|
50
|
+
* Use this to skip or preprocess the Keyword for the given JSON Schema and
|
|
51
|
+
* to create any schema annotations, like input errors.
|
|
52
|
+
*
|
|
53
|
+
* - most keywords cache their evaluation directly on node, e.g. node.required
|
|
54
|
+
* - most keywords skip any other actions if their evaluation is missing on node
|
|
55
|
+
* - return any errors found in JSON schema related to this keyword
|
|
56
|
+
* (this includes errors from created nodes)
|
|
57
|
+
*/
|
|
58
|
+
parse?: (node: SchemaNode) => void | ValidationAnnotation | ValidationAnnotation[];
|
|
59
|
+
addResolve?: (node: SchemaNode) => boolean;
|
|
60
|
+
/**
|
|
61
|
+
* If this contains child-data, resolve must return schema associated for the passed in key
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* a keyword properties has has child-properties. So when a properties[key] exists,
|
|
65
|
+
* it will return the node of properties[key] or nothing at all
|
|
66
|
+
*/
|
|
67
|
+
resolve?: JsonSchemaResolver; /** return true if the given node should run the validate-function on this keyword */
|
|
68
|
+
addValidate?: (node: SchemaNode) => boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Perform validation for this keyword and the passed in data
|
|
71
|
+
*/
|
|
72
|
+
validate?: JsonSchemaValidator<Key>;
|
|
73
|
+
addReduce?: (node: SchemaNode) => boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Remove dynamic schema-keywords by merging valid sub-schemas
|
|
76
|
+
*/
|
|
53
77
|
reduce?: JsonSchemaReducer;
|
|
54
78
|
};
|
|
55
79
|
//#endregion
|
|
@@ -196,6 +220,8 @@ declare const errors: {
|
|
|
196
220
|
"unknown-property-error": string;
|
|
197
221
|
"value-not-empty-error": string;
|
|
198
222
|
"deprecated-warning": string;
|
|
223
|
+
"schema-error": string;
|
|
224
|
+
"unknown-keyword-warning": string;
|
|
199
225
|
};
|
|
200
226
|
//#endregion
|
|
201
227
|
//#region src/SchemaNode.d.ts
|
|
@@ -213,7 +239,8 @@ type Context = {
|
|
|
213
239
|
version: Draft["version"]; /** draft errors & template-strings */
|
|
214
240
|
errors: Draft["errors"]; /** draft formats & validators */
|
|
215
241
|
formats: Draft["formats"]; /** [SHARED USING ADD REMOTE] getData default options */
|
|
216
|
-
getDataDefaultOptions?: TemplateOptions;
|
|
242
|
+
getDataDefaultOptions?: TemplateOptions; /** [SHARED USING ADD REMOTE] collect unknown keywords in schemaAnnotations */
|
|
243
|
+
withSchemaAnnotations?: boolean;
|
|
217
244
|
};
|
|
218
245
|
interface SchemaNode extends SchemaNodeMethodsType {
|
|
219
246
|
/** shared context across nodes of JSON schema and shared properties across all remotes */
|
|
@@ -250,6 +277,7 @@ interface SchemaNode extends SchemaNodeMethodsType {
|
|
|
250
277
|
reducers: JsonSchemaReducer[];
|
|
251
278
|
resolvers: JsonSchemaResolver[];
|
|
252
279
|
validators: JsonSchemaValidator[];
|
|
280
|
+
schemaValidation?: ValidationAnnotation[];
|
|
253
281
|
$id?: string;
|
|
254
282
|
$defs?: Record<string, SchemaNode>;
|
|
255
283
|
$ref?: string;
|
|
@@ -259,7 +287,9 @@ interface SchemaNode extends SchemaNodeMethodsType {
|
|
|
259
287
|
contains?: SchemaNode;
|
|
260
288
|
dependentRequired?: Record<string, string[]>;
|
|
261
289
|
dependentSchemas?: Record<string, SchemaNode | boolean>;
|
|
290
|
+
deprecated?: boolean;
|
|
262
291
|
else?: SchemaNode;
|
|
292
|
+
enum?: unknown[];
|
|
263
293
|
if?: SchemaNode;
|
|
264
294
|
/**
|
|
265
295
|
* # Items-array schema - for all drafts
|
|
@@ -296,18 +326,32 @@ interface SchemaNode extends SchemaNodeMethodsType {
|
|
|
296
326
|
* | [AdditionalItems Specification](https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#additionalItems)
|
|
297
327
|
*/
|
|
298
328
|
items?: SchemaNode;
|
|
329
|
+
maximum?: number;
|
|
330
|
+
minimum?: number;
|
|
331
|
+
maxItems?: number;
|
|
332
|
+
maxLength?: number;
|
|
333
|
+
maxProperties?: number;
|
|
334
|
+
minItems?: number;
|
|
335
|
+
minLength?: number;
|
|
336
|
+
minProperties?: number;
|
|
299
337
|
not?: SchemaNode;
|
|
300
338
|
oneOf?: SchemaNode[];
|
|
339
|
+
multipleOf?: number;
|
|
340
|
+
pattern?: RegExp;
|
|
301
341
|
patternProperties?: {
|
|
302
342
|
name: string;
|
|
303
343
|
pattern: RegExp;
|
|
304
344
|
node: SchemaNode;
|
|
305
345
|
}[];
|
|
346
|
+
propertyDependencies?: Record<string, Record<string, SchemaNode>>;
|
|
306
347
|
properties?: Record<string, SchemaNode>;
|
|
307
348
|
propertyNames?: SchemaNode;
|
|
349
|
+
required?: string[];
|
|
308
350
|
then?: SchemaNode;
|
|
351
|
+
type?: string | string[];
|
|
309
352
|
unevaluatedItems?: SchemaNode;
|
|
310
353
|
unevaluatedProperties?: SchemaNode;
|
|
354
|
+
uniqueItems?: true;
|
|
311
355
|
}
|
|
312
356
|
/**
|
|
313
357
|
* Fixed SchemaNode mixin methods
|
|
@@ -466,14 +510,19 @@ type CompileOptions = {
|
|
|
466
510
|
drafts?: Draft[];
|
|
467
511
|
remote?: SchemaNode;
|
|
468
512
|
formatAssertion?: boolean | "meta-schema" | undefined;
|
|
469
|
-
getDataDefaultOptions?: TemplateOptions;
|
|
513
|
+
getDataDefaultOptions?: TemplateOptions; /** set to true to throw an Errors on errors in input schema. Defaults to false */
|
|
514
|
+
throwOnInvalidSchema?: boolean; /** set to true to collect unknown keywords of input schema in `node.schemaAnnotations`. Defaults to false */
|
|
515
|
+
withSchemaAnnotations?: boolean;
|
|
470
516
|
};
|
|
471
517
|
/**
|
|
472
518
|
* With compileSchema we replace the schema and all sub-schemas with a schemaNode,
|
|
473
519
|
* wrapping each schema with utilities and as much preevaluation as possible. Each
|
|
474
520
|
* node will be reused for each task, but will create a compiledNode for bound data.
|
|
475
521
|
*/
|
|
476
|
-
declare function compileSchema(schema: JsonSchema | BooleanSchema, options?: CompileOptions): SchemaNode
|
|
522
|
+
declare function compileSchema(schema: JsonSchema | BooleanSchema, options?: CompileOptions): SchemaNode & {
|
|
523
|
+
schemaErrors?: JsonError[];
|
|
524
|
+
schemaAnnotations: JsonAnnotation[];
|
|
525
|
+
};
|
|
477
526
|
//#endregion
|
|
478
527
|
//#region src/settings.d.ts
|
|
479
528
|
declare const _default: {
|
|
@@ -601,6 +650,34 @@ declare const draftEditor: Draft;
|
|
|
601
650
|
declare const oneOfKeyword: Keyword;
|
|
602
651
|
declare const oneOfFuzzyKeyword: Keyword;
|
|
603
652
|
//#endregion
|
|
653
|
+
//#region src/keywords/propertyDependencies.d.ts
|
|
654
|
+
/**
|
|
655
|
+
* @experimental `propertyDependencies` to resolve schema by nested name and value
|
|
656
|
+
* @reference https://docs.google.com/presentation/d/1ajXlCQcsjjiMLsluFIILR7sN5aDRBnfqQ9DLbcFbqjI/mobilepresent?slide=id.p
|
|
657
|
+
*
|
|
658
|
+
* - matching schemas are resolved and validiated
|
|
659
|
+
* - multiple matching schemas are resolved and validiated
|
|
660
|
+
* - ignores keyword if no schema is matched
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* {
|
|
664
|
+
* type: "object",
|
|
665
|
+
* propertyDependencies: {
|
|
666
|
+
* propertyName: {
|
|
667
|
+
* propertyValue: { $ref: "#/$defs/schema" }
|
|
668
|
+
* }
|
|
669
|
+
* }
|
|
670
|
+
* }
|
|
671
|
+
*
|
|
672
|
+
* matches
|
|
673
|
+
*
|
|
674
|
+
* {
|
|
675
|
+
* "propertyName": "propertyValue",
|
|
676
|
+
* "otherData": 123
|
|
677
|
+
* } with "#/$defs/schema"
|
|
678
|
+
*/
|
|
679
|
+
declare const propertyDependenciesKeyword: Keyword;
|
|
680
|
+
//#endregion
|
|
604
681
|
//#region src/errors/render.d.ts
|
|
605
682
|
declare function render(template: string, data?: Record<string, unknown>): string;
|
|
606
683
|
//#endregion
|
|
@@ -634,4 +711,4 @@ declare function sanitizeErrors(list: ValidationReturnType | ValidationReturnTyp
|
|
|
634
711
|
/** remote meta-schema stored by schema $id */
|
|
635
712
|
declare const remotes: Record<string, any>;
|
|
636
713
|
//#endregion
|
|
637
|
-
export { type Annotation, type AnnotationData, type BooleanSchema, type CompileOptions, type Context, type DataNode, type Draft, type DraftVersion, type ErrorConfig, type GetNodeOptions, type JsonAnnotation, type JsonError, type JsonPointer, type JsonSchema, type JsonSchemaReducer, type JsonSchemaReducerParams, type JsonSchemaResolver, type JsonSchemaResolverParams, type JsonSchemaValidator, type JsonSchemaValidatorParams, type Keyword, type Maybe, type NodeOrError, type OptionalNodeOrError, type SchemaNode, type ValidateReturnType, type ValidationAnnotation, type ValidationPath, type ValidationReturnType, addKeywords, compileSchema, draft04, draft06, draft07, draft2019, draft2020, draftEditor, extendDraft, getSchemaType, getTypeOf, isAnnotation, isBooleanSchema, isJsonAnnotation, isJsonError, isJsonSchema, isReduceable, isSchemaNode, mergeNode, mergeSchema, oneOfFuzzyKeyword, oneOfKeyword, remotes, render, sanitizeErrors, _default as settings };
|
|
714
|
+
export { type Annotation, type AnnotationData, type BooleanSchema, type CompileOptions, type Context, type DataNode, type Draft, type DraftVersion, type ErrorConfig, type GetNodeOptions, type JsonAnnotation, type JsonError, type JsonPointer, type JsonSchema, type JsonSchemaReducer, type JsonSchemaReducerParams, type JsonSchemaResolver, type JsonSchemaResolverParams, type JsonSchemaValidator, type JsonSchemaValidatorParams, type Keyword, type Maybe, type NodeOrError, type OptionalNodeOrError, type SchemaNode, type ValidateReturnType, type ValidationAnnotation, type ValidationPath, type ValidationReturnType, addKeywords, compileSchema, draft04, draft06, draft07, draft2019, draft2020, draftEditor, extendDraft, getSchemaType, getTypeOf, isAnnotation, isBooleanSchema, isJsonAnnotation, isJsonError, isJsonSchema, isReduceable, isSchemaNode, mergeNode, mergeSchema, oneOfFuzzyKeyword, oneOfKeyword, propertyDependenciesKeyword, remotes, render, sanitizeErrors, _default as settings };
|
package/dist/index.d.mts
CHANGED
|
@@ -29,27 +29,51 @@ type Maybe<T> = T | undefined;
|
|
|
29
29
|
type ValidationAnnotation = JsonError | JsonAnnotation | Promise<Maybe<ValidationAnnotation>[]>;
|
|
30
30
|
type ValidationResult = Maybe<ValidationAnnotation>;
|
|
31
31
|
type ValidationReturnType = ValidationResult | ValidationResult[];
|
|
32
|
-
type
|
|
32
|
+
type SchemaNodeWithRequired<K extends keyof SchemaNode> = SchemaNode & Required<Pick<SchemaNode, K>>;
|
|
33
|
+
type JsonSchemaValidatorParams<Key extends keyof SchemaNode = keyof SchemaNode> = {
|
|
33
34
|
pointer: string;
|
|
34
35
|
data: unknown;
|
|
35
|
-
node:
|
|
36
|
+
node: SchemaNodeWithRequired<Key>;
|
|
36
37
|
path: ValidationPath;
|
|
37
38
|
};
|
|
38
|
-
interface JsonSchemaValidator {
|
|
39
|
+
interface JsonSchemaValidator<Key extends keyof SchemaNode = keyof SchemaNode> {
|
|
39
40
|
toJSON?: () => string;
|
|
40
41
|
order?: number;
|
|
41
|
-
(options: JsonSchemaValidatorParams): ValidationReturnType;
|
|
42
|
+
(options: JsonSchemaValidatorParams<Key>): ValidationReturnType;
|
|
42
43
|
}
|
|
43
|
-
type Keyword = {
|
|
44
|
+
type Keyword<Key extends keyof SchemaNode = keyof SchemaNode> = {
|
|
44
45
|
id: string; /** unique keyword corresponding to JSON Schema keywords (or custom) */
|
|
45
46
|
keyword: string; /** sort order of keyword. Lower numbers will be processed last. Default is 0 */
|
|
46
|
-
order?: number;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
order?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Called once for each JSON Schema dduring compileSchema to evaluate keyword.
|
|
50
|
+
* Use this to skip or preprocess the Keyword for the given JSON Schema and
|
|
51
|
+
* to create any schema annotations, like input errors.
|
|
52
|
+
*
|
|
53
|
+
* - most keywords cache their evaluation directly on node, e.g. node.required
|
|
54
|
+
* - most keywords skip any other actions if their evaluation is missing on node
|
|
55
|
+
* - return any errors found in JSON schema related to this keyword
|
|
56
|
+
* (this includes errors from created nodes)
|
|
57
|
+
*/
|
|
58
|
+
parse?: (node: SchemaNode) => void | ValidationAnnotation | ValidationAnnotation[];
|
|
59
|
+
addResolve?: (node: SchemaNode) => boolean;
|
|
60
|
+
/**
|
|
61
|
+
* If this contains child-data, resolve must return schema associated for the passed in key
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* a keyword properties has has child-properties. So when a properties[key] exists,
|
|
65
|
+
* it will return the node of properties[key] or nothing at all
|
|
66
|
+
*/
|
|
67
|
+
resolve?: JsonSchemaResolver; /** return true if the given node should run the validate-function on this keyword */
|
|
68
|
+
addValidate?: (node: SchemaNode) => boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Perform validation for this keyword and the passed in data
|
|
71
|
+
*/
|
|
72
|
+
validate?: JsonSchemaValidator<Key>;
|
|
73
|
+
addReduce?: (node: SchemaNode) => boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Remove dynamic schema-keywords by merging valid sub-schemas
|
|
76
|
+
*/
|
|
53
77
|
reduce?: JsonSchemaReducer;
|
|
54
78
|
};
|
|
55
79
|
//#endregion
|
|
@@ -196,6 +220,8 @@ declare const errors: {
|
|
|
196
220
|
"unknown-property-error": string;
|
|
197
221
|
"value-not-empty-error": string;
|
|
198
222
|
"deprecated-warning": string;
|
|
223
|
+
"schema-error": string;
|
|
224
|
+
"unknown-keyword-warning": string;
|
|
199
225
|
};
|
|
200
226
|
//#endregion
|
|
201
227
|
//#region src/SchemaNode.d.ts
|
|
@@ -213,7 +239,8 @@ type Context = {
|
|
|
213
239
|
version: Draft["version"]; /** draft errors & template-strings */
|
|
214
240
|
errors: Draft["errors"]; /** draft formats & validators */
|
|
215
241
|
formats: Draft["formats"]; /** [SHARED USING ADD REMOTE] getData default options */
|
|
216
|
-
getDataDefaultOptions?: TemplateOptions;
|
|
242
|
+
getDataDefaultOptions?: TemplateOptions; /** [SHARED USING ADD REMOTE] collect unknown keywords in schemaAnnotations */
|
|
243
|
+
withSchemaAnnotations?: boolean;
|
|
217
244
|
};
|
|
218
245
|
interface SchemaNode extends SchemaNodeMethodsType {
|
|
219
246
|
/** shared context across nodes of JSON schema and shared properties across all remotes */
|
|
@@ -250,6 +277,7 @@ interface SchemaNode extends SchemaNodeMethodsType {
|
|
|
250
277
|
reducers: JsonSchemaReducer[];
|
|
251
278
|
resolvers: JsonSchemaResolver[];
|
|
252
279
|
validators: JsonSchemaValidator[];
|
|
280
|
+
schemaValidation?: ValidationAnnotation[];
|
|
253
281
|
$id?: string;
|
|
254
282
|
$defs?: Record<string, SchemaNode>;
|
|
255
283
|
$ref?: string;
|
|
@@ -259,7 +287,9 @@ interface SchemaNode extends SchemaNodeMethodsType {
|
|
|
259
287
|
contains?: SchemaNode;
|
|
260
288
|
dependentRequired?: Record<string, string[]>;
|
|
261
289
|
dependentSchemas?: Record<string, SchemaNode | boolean>;
|
|
290
|
+
deprecated?: boolean;
|
|
262
291
|
else?: SchemaNode;
|
|
292
|
+
enum?: unknown[];
|
|
263
293
|
if?: SchemaNode;
|
|
264
294
|
/**
|
|
265
295
|
* # Items-array schema - for all drafts
|
|
@@ -296,18 +326,32 @@ interface SchemaNode extends SchemaNodeMethodsType {
|
|
|
296
326
|
* | [AdditionalItems Specification](https://json-schema.org/draft/2019-09/draft-handrews-json-schema-02#additionalItems)
|
|
297
327
|
*/
|
|
298
328
|
items?: SchemaNode;
|
|
329
|
+
maximum?: number;
|
|
330
|
+
minimum?: number;
|
|
331
|
+
maxItems?: number;
|
|
332
|
+
maxLength?: number;
|
|
333
|
+
maxProperties?: number;
|
|
334
|
+
minItems?: number;
|
|
335
|
+
minLength?: number;
|
|
336
|
+
minProperties?: number;
|
|
299
337
|
not?: SchemaNode;
|
|
300
338
|
oneOf?: SchemaNode[];
|
|
339
|
+
multipleOf?: number;
|
|
340
|
+
pattern?: RegExp;
|
|
301
341
|
patternProperties?: {
|
|
302
342
|
name: string;
|
|
303
343
|
pattern: RegExp;
|
|
304
344
|
node: SchemaNode;
|
|
305
345
|
}[];
|
|
346
|
+
propertyDependencies?: Record<string, Record<string, SchemaNode>>;
|
|
306
347
|
properties?: Record<string, SchemaNode>;
|
|
307
348
|
propertyNames?: SchemaNode;
|
|
349
|
+
required?: string[];
|
|
308
350
|
then?: SchemaNode;
|
|
351
|
+
type?: string | string[];
|
|
309
352
|
unevaluatedItems?: SchemaNode;
|
|
310
353
|
unevaluatedProperties?: SchemaNode;
|
|
354
|
+
uniqueItems?: true;
|
|
311
355
|
}
|
|
312
356
|
/**
|
|
313
357
|
* Fixed SchemaNode mixin methods
|
|
@@ -466,14 +510,19 @@ type CompileOptions = {
|
|
|
466
510
|
drafts?: Draft[];
|
|
467
511
|
remote?: SchemaNode;
|
|
468
512
|
formatAssertion?: boolean | "meta-schema" | undefined;
|
|
469
|
-
getDataDefaultOptions?: TemplateOptions;
|
|
513
|
+
getDataDefaultOptions?: TemplateOptions; /** set to true to throw an Errors on errors in input schema. Defaults to false */
|
|
514
|
+
throwOnInvalidSchema?: boolean; /** set to true to collect unknown keywords of input schema in `node.schemaAnnotations`. Defaults to false */
|
|
515
|
+
withSchemaAnnotations?: boolean;
|
|
470
516
|
};
|
|
471
517
|
/**
|
|
472
518
|
* With compileSchema we replace the schema and all sub-schemas with a schemaNode,
|
|
473
519
|
* wrapping each schema with utilities and as much preevaluation as possible. Each
|
|
474
520
|
* node will be reused for each task, but will create a compiledNode for bound data.
|
|
475
521
|
*/
|
|
476
|
-
declare function compileSchema(schema: JsonSchema | BooleanSchema, options?: CompileOptions): SchemaNode
|
|
522
|
+
declare function compileSchema(schema: JsonSchema | BooleanSchema, options?: CompileOptions): SchemaNode & {
|
|
523
|
+
schemaErrors?: JsonError[];
|
|
524
|
+
schemaAnnotations: JsonAnnotation[];
|
|
525
|
+
};
|
|
477
526
|
//#endregion
|
|
478
527
|
//#region src/settings.d.ts
|
|
479
528
|
declare const _default: {
|
|
@@ -601,6 +650,34 @@ declare const draftEditor: Draft;
|
|
|
601
650
|
declare const oneOfKeyword: Keyword;
|
|
602
651
|
declare const oneOfFuzzyKeyword: Keyword;
|
|
603
652
|
//#endregion
|
|
653
|
+
//#region src/keywords/propertyDependencies.d.ts
|
|
654
|
+
/**
|
|
655
|
+
* @experimental `propertyDependencies` to resolve schema by nested name and value
|
|
656
|
+
* @reference https://docs.google.com/presentation/d/1ajXlCQcsjjiMLsluFIILR7sN5aDRBnfqQ9DLbcFbqjI/mobilepresent?slide=id.p
|
|
657
|
+
*
|
|
658
|
+
* - matching schemas are resolved and validiated
|
|
659
|
+
* - multiple matching schemas are resolved and validiated
|
|
660
|
+
* - ignores keyword if no schema is matched
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
* {
|
|
664
|
+
* type: "object",
|
|
665
|
+
* propertyDependencies: {
|
|
666
|
+
* propertyName: {
|
|
667
|
+
* propertyValue: { $ref: "#/$defs/schema" }
|
|
668
|
+
* }
|
|
669
|
+
* }
|
|
670
|
+
* }
|
|
671
|
+
*
|
|
672
|
+
* matches
|
|
673
|
+
*
|
|
674
|
+
* {
|
|
675
|
+
* "propertyName": "propertyValue",
|
|
676
|
+
* "otherData": 123
|
|
677
|
+
* } with "#/$defs/schema"
|
|
678
|
+
*/
|
|
679
|
+
declare const propertyDependenciesKeyword: Keyword;
|
|
680
|
+
//#endregion
|
|
604
681
|
//#region src/errors/render.d.ts
|
|
605
682
|
declare function render(template: string, data?: Record<string, unknown>): string;
|
|
606
683
|
//#endregion
|
|
@@ -634,4 +711,4 @@ declare function sanitizeErrors(list: ValidationReturnType | ValidationReturnTyp
|
|
|
634
711
|
/** remote meta-schema stored by schema $id */
|
|
635
712
|
declare const remotes: Record<string, any>;
|
|
636
713
|
//#endregion
|
|
637
|
-
export { type Annotation, type AnnotationData, type BooleanSchema, type CompileOptions, type Context, type DataNode, type Draft, type DraftVersion, type ErrorConfig, type GetNodeOptions, type JsonAnnotation, type JsonError, type JsonPointer, type JsonSchema, type JsonSchemaReducer, type JsonSchemaReducerParams, type JsonSchemaResolver, type JsonSchemaResolverParams, type JsonSchemaValidator, type JsonSchemaValidatorParams, type Keyword, type Maybe, type NodeOrError, type OptionalNodeOrError, type SchemaNode, type ValidateReturnType, type ValidationAnnotation, type ValidationPath, type ValidationReturnType, addKeywords, compileSchema, draft04, draft06, draft07, draft2019, draft2020, draftEditor, extendDraft, getSchemaType, getTypeOf, isAnnotation, isBooleanSchema, isJsonAnnotation, isJsonError, isJsonSchema, isReduceable, isSchemaNode, mergeNode, mergeSchema, oneOfFuzzyKeyword, oneOfKeyword, remotes, render, sanitizeErrors, _default as settings };
|
|
714
|
+
export { type Annotation, type AnnotationData, type BooleanSchema, type CompileOptions, type Context, type DataNode, type Draft, type DraftVersion, type ErrorConfig, type GetNodeOptions, type JsonAnnotation, type JsonError, type JsonPointer, type JsonSchema, type JsonSchemaReducer, type JsonSchemaReducerParams, type JsonSchemaResolver, type JsonSchemaResolverParams, type JsonSchemaValidator, type JsonSchemaValidatorParams, type Keyword, type Maybe, type NodeOrError, type OptionalNodeOrError, type SchemaNode, type ValidateReturnType, type ValidationAnnotation, type ValidationPath, type ValidationReturnType, addKeywords, compileSchema, draft04, draft06, draft07, draft2019, draft2020, draftEditor, extendDraft, getSchemaType, getTypeOf, isAnnotation, isBooleanSchema, isJsonAnnotation, isJsonError, isJsonSchema, isReduceable, isSchemaNode, mergeNode, mergeSchema, oneOfFuzzyKeyword, oneOfKeyword, propertyDependenciesKeyword, remotes, render, sanitizeErrors, _default as settings };
|