@@ -125,7 +125,10 @@ export type GetSchemaOptions = {
125
125
} ;
126
126
127
127
export const SchemaNodeMethods = {
128
- /** Compiles a child-schema of this node to its context */
128
+ /**
129
+ * Compiles a child-schema of this node to its context
130
+ * @returns SchemaNode representing the passed JSON Schema
131
+ */
129
132
compileSchema ( schema : JsonSchema , spointer : string = this . spointer , schemaId ?: string ) : SchemaNode {
130
133
const nextFragment = spointer . split ( "/$ref" ) [ 0 ] ;
131
134
const parentNode = this as SchemaNode ;
@@ -156,7 +159,7 @@ export const SchemaNodeMethods = {
156
159
}
157
160
errorMessage = render ( error ?? name , data ) ;
158
161
}
159
- return { type : "error" , name , code : dashCase ( name ) , message : errorMessage , data } ;
162
+ return { type : "error" , code : dashCase ( name ) , message : errorMessage , data } ;
160
163
} ,
161
164
162
165
createSchema,
@@ -216,11 +219,17 @@ export const SchemaNodeMethods = {
216
219
return isJsonError ( result ) ? { node : undefined , error : result } : { node : result , error : undefined } ;
217
220
} ,
218
221
222
+ /**
223
+ * @returns for $ref, the corresponding SchemaNode or undefined
224
+ */
219
225
getRef ( $ref : string ) : SchemaNode | undefined {
220
226
const node = this as SchemaNode ;
221
227
return node . compileSchema ( { $ref } ) . resolveRef ( ) ;
222
228
} ,
223
229
230
+ /**
231
+ * @returns child node identified by property as SchemaNode
232
+ */
224
233
getChild ( key : string | number , data ?: unknown , options : GetSchemaOptions = { } ) : OptionalNodeAndError {
225
234
options . path = options . path ?? [ ] ;
226
235
@@ -271,11 +280,16 @@ export const SchemaNodeMethods = {
271
280
return { node : undefined , error : undefined } ;
272
281
} ,
273
282
283
+ /**
284
+ * @returns draft version this JSON Schema is evaluated by
285
+ */
274
286
getDraftVersion ( ) {
275
287
return ( this as SchemaNode ) . context . version ;
276
288
} ,
277
289
278
- /** Creates data that is valid to the schema of this node */
290
+ /**
291
+ * @returns data that is valid to the schema of this node
292
+ */
279
293
getData ( data ?: unknown , options ?: TemplateOptions ) {
280
294
const node = this as SchemaNode ;
281
295
const opts = {
@@ -287,6 +301,9 @@ export const SchemaNodeMethods = {
287
301
return node . context . methods . getData ( node , data , opts ) ;
288
302
} ,
289
303
304
+ /**
305
+ * @returns SchemaNode with a reduced JSON Schema matching the given data
306
+ */
290
307
reduceSchema (
291
308
data : unknown ,
292
309
options : { key ?: string | number ; pointer ?: string ; path ?: ValidationPath } = { }
@@ -343,7 +360,9 @@ export const SchemaNodeMethods = {
343
360
return { node : workingNode , error : undefined } ;
344
361
} ,
345
362
346
- /** Creates a new node with all dynamic schema properties merged according to the passed in data */
363
+ /**
364
+ * @returns validation result of data validated by this node's JSON Schema
365
+ */
347
366
validate ( data : unknown , pointer = "#" , path : ValidationPath = [ ] ) : { valid : boolean ; errors : JsonError [ ] } {
348
367
const errors = validateNode ( this , data , pointer , path ) ?? [ ] ;
349
368
const flatErrorList = sanitizeErrors ( Array . isArray ( errors ) ? errors : [ errors ] ) . filter ( isJsonError ) ;
@@ -353,6 +372,9 @@ export const SchemaNodeMethods = {
353
372
} ;
354
373
} ,
355
374
375
+ /**
376
+ * @returns a promise which resolves to validation-result
377
+ */
356
378
async validateAsync (
357
379
data : unknown ,
358
380
pointer = "#" ,
@@ -401,10 +423,16 @@ export const SchemaNodeMethods = {
401
423
return this ;
402
424
} ,
403
425
426
+ /**
427
+ * @returns a list of all sub-schema as SchemaNode
428
+ */
404
429
toSchemaNodes ( ) {
405
430
return toSchemaNodes ( this as SchemaNode ) ;
406
431
} ,
407
432
433
+ /**
434
+ * @returns a list of values (including objects and arrays) and their corresponding JSON Schema as SchemaNode
435
+ */
408
436
toDataNodes ( data : unknown , pointer ?: string ) {
409
437
const node = this as SchemaNode ;
410
438
return node . context . methods . toDataNodes ( node , data , pointer ) ;
0 commit comments