Skip to content

Commit d1c17ac

Browse files
authored
Merge pull request #12 from gregsdennis/schema-options
improve schema options docs
2 parents 8b574ef + 69fea74 commit d1c17ac

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

_docs/schema/basics.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,54 @@ New formats must be registered via the `Formats.Register()` static method. This
446446

447447
## Options {#schema-options}
448448

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+
449454
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.
450455

451456
- `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.
452457
- `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. \*
453458
- `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.
459+
- `RequireFormatValidation` - Forces `format` validation.
460+
- `OnlyKnownFormats` - Limits `format` validation to only those formats which have been registered through `Formats.Register()`. Unknown formats will fail validation.
454461
- `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.
455464

456465
_\* 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._
457466

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+
458497
# Managing references (`$ref`) {#schema-ref}
459498

460499
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
645684
646685
Currently available translations are:
647686
648-
- Norwegian
649-
- Spanish
650-
- Swedish
651-
- Turkish
687+
| Language | Culture Code |
688+
|:-|:-:|
689+
|Norwegian|`nb-NO`|
690+
|Russian|`ru`|
691+
|Spanish|`es`|
692+
|Swedish|`sv-SE`|
693+
|Turkish|`tr-TR`|
652694
653695
PRs are welcome to help create additional translations.

0 commit comments

Comments
 (0)