You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _docs/schema/basics.md
+46-4Lines changed: 46 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -446,15 +446,54 @@ New formats must be registered via the `Formats.Register()` static method. This
446
446
447
447
## Options {#schema-options}
448
448
449
+
> For the best performance, use a cached evaluation options object.
450
+
>
451
+
> *JsonSchema.Net* optimizes repeated evaluations with the same schema by performing some static analysis during the first evaluation. However because changes to evaluation options can affect this analysis, the analysis is recalculated if the options change or a new options object is detected.
452
+
{: .prompt-warn }
453
+
449
454
The `EvaluationOptions` class gives you a few configuration points for customizing how the evaluation process behaves. It is an instance class and can be passed into the `JsonSchema.Evaluate()` method. If no options are explicitly passed, a copy of `JsonSchemaOptions.Default` will be used.
450
455
451
456
-`EvaluateAs` - Indicates which schema version to process as. This will filter the keywords of a schema based on their support. This means that if any keyword is not supported by this version, it will be ignored.
452
457
-`EvaluateMetaSchema` - Indicates whether the schema should be evaluated against its `$schema` value (its meta-schema). This is not typically necessary. Note that the evaluation process will still attempt to resolve the meta-schema. \*
453
458
-`OutputFormat` - You already read about output formats above. This is the property that controls it all. By default, a single "flag" node is returned. This also yields the fastest evaluation times as it enables certain optimizations.
-`OnlyKnownFormats` - Limits `format` validation to only those formats which have been registered through `Formats.Register()`. Unknown formats will fail validation.
454
461
-`ProcessCustomKeywords` - For schema versions which support the vocabulary system (i.g. 2019-09 and after), allows custom keywords to be processed which haven't been included in a vocabulary. This still requires the keyword type to be registered with `SchemaRegistry`.
462
+
-`PreserveDroppedAnnotations` - Adds a `droppedAnnotations` property to the output nodes for subschemas that fail validation.
463
+
-`IgnoredAnnotations` - Gets the set of annotations that will be excluded from the output.
455
464
456
465
_\* If you're using a custom meta-schema, you'll need to load it per the [Schema Registration](json-schema#schema-registration) section below. Custom meta-schemas form a chain of meta-schemas (e.g. your custom meta-schema may reference another which references the draft 2020-12 meta-schema). Ultimately, the chain MUST end at a JSON-Schema-defined meta-schema as this defines the processing rules for the schema. An error will be produced if the meta-schema chain ends at a meta-schema that is unrecognized._
457
466
467
+
### Annotation management {#annotation-mgmt}
468
+
469
+
Several in the JSON Schema community have raised issues that collecting annotations can be costly in both memory consumption and time. As such, one proposal has been to allow for filtering which annotation are collected and reported in the output.
470
+
471
+
> Some annotations, like those for `properties`, are still collected but not reported as they are required for other keywords, like `unevaluatedProperties`, to operate.
472
+
473
+
By default, all annotations are collected.
474
+
475
+
The following methods allow you to manage the set of annotations to collect and report.
476
+
477
+
-`.IgnoreAnnotationsFrom<T>()` - Ignores annotations from the specified keyword.
478
+
-`.IgnoreAllAnnotations()` - Ignores all annotations.
479
+
-`.ClearIgnoredAnnotations()` - Clears the "ignore" set and collects all annotations.
480
+
-`.CollectAnnotationsFrom<T>()` - Collects annotations from the specified keyword.
481
+
482
+
These methods make it easy to either ignore or collect annotations from a single or a few keywords.
483
+
484
+
For example, to ignore `title` annotations:
485
+
486
+
```c#
487
+
options.IgnoreAnnotationsFrom<TitleKeyword>();
488
+
```
489
+
490
+
Or to only collect `title` annotations:
491
+
492
+
```c#
493
+
options.IgnoreAllAnnotations();
494
+
options.CollectAnnotationsFrom<TitleKeyword>();
495
+
```
496
+
458
497
# Managing references (`$ref`) {#schema-ref}
459
498
460
499
By default, *JsonSchema.Net* handles all references as defined in the draft 2020-12 version of the JSON Schema specification. What this means for draft 2019-09 and later schemas is that `$ref` can now exist alongside other keywords; for earlier versions (i.e. Drafts 6 and 7), keywords as siblings to `$ref` will be ignored.
@@ -645,9 +684,12 @@ var options = new EvaluationOptions
0 commit comments