Skip to content

Commit ef12c66

Browse files
committed
add explicit anchors to docs (schema)
1 parent 36ab654 commit ef12c66

File tree

9 files changed

+88
-88
lines changed

9 files changed

+88
-88
lines changed

json-everything.net/Shared/Docs.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
[Parameter]
1919
public string? Page { get; set; }
2020

21-
private const string _headerLinkPattern = "<h$1 id=\"$2\">$3<a id=\"user-content-syntax\" class=\"markdown-anchor m-2\" aria-hidden=\"true\" href=\"[[localPath]]#$2\"><svg class=\"markdown-anchor\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path fill-rule=\"evenodd\" d=\"M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z\"></path></svg></a></h$1>";
21+
private const string _headerLinkPattern = "<h$1 id=\"$2\">$3<a id=\"user-content-syntax\" class=\"markdown-anchor m-2\" aria-hidden=\"true\" href=\"[[localPath]]#$2\"><svg class=\"markdown-anchor\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path fill-rule=\"evenodd\" d=\"M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z\"></path></svg></a></h$1>";
2222
private static readonly Regex _tablePattern = new(@"<table>");
2323

2424
private string _value = "";

json-everything.net/wwwroot/md/schema-basics.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Overview
1+
# Overview {#schema-basics}
22

33
The occasion may arise when you wish to validate that a JSON object is in the correct form (has the appropriate keys and the right types of values), or perhaps you wish to annotate that data. Enter JSON Schema. Much like XML Schema with XML, JSON Schema defines a pattern for JSON data. A JSON Schema validator can verify that a given JSON object meets the requirements as defined by the JSON Schema as well as provide additional information to the application about the data. This evaluation can come in handy as a precursor step before deserializing.
44

55
More information about JSON Schema can be found at [json-schema.org](http://json-schema.org).
66

77
To support JSON Schema, JsonSchema.Net exposes the `JsonSchema` type. This type is implemented as a list of keywords, each of which correspond to one of the keywords defined in the JSON Schema specifications.
88

9-
## Specification versions
9+
## Specification versions {#schema-versions}
1010

1111
There are currently six drafts of the JSON Schema specification that have known use:
1212

@@ -21,23 +21,23 @@ JsonSchema.Net supports draft 6 and later.
2121

2222
The next version, which will be supported by v4.0.0 and later of this library, is currently in development and will start a new era for the project which includes various backward- and forward-compatibility guarantees. Have a read of the various discussions happening in the [JSON Schema GitHub org](https://github.com/json-schema-org) for more information.
2323

24-
### Meta-schemas
24+
### Meta-schemas {#schema-metaschemas}
2525

2626
Each version defines a meta-schema. This is a special JSON Schema that describes all of the keywords available for that version. They are intended to be used to validate other schemas. Usually, a schema will declare the version it should adhere to using the `$schema` keyword.
2727

2828
JsonSchema.Net declares the meta-schemas for the supported versions as members of the `MetaSchemas` static class.
2929

3030
Draft 2019-09 introduced vocabularies. As part of this new feature, the meta-schemas for this version and those which follow it have been split into vocabulary-specific meta-schemas. Additionally, the specification recognizes that the meta-schemas aren't perfect and may need to be updated occasionally. As such, the meta-schemas defined by this library will be updated to match, in most cases only triggering a patch release.
3131

32-
## Keywords
32+
## Keywords {#schema-keywords}
3333

3434
JSON Schema is expressed as a collection of keywords, each of which provides a specific constraint on a JSON instance. For example, the `type` keyword specifies what JSON type an instance may be, whereas the `minimum` keyword specifies a minimum numeric value *for only numeric data* (it will not apply any assertion to non-numeric values). These keywords can be combined to express the expected shape of any JSON instance. Once defined, the schema evaluates the instance, providing feedback on what errors occurred, including where in the instance and in the schema produced them.
3535

36-
# Building a schema
36+
# Building a schema {#schema-build}
3737

3838
There are two options when building a schema: defining it inline using the fluent builder and defining it externally and deserializing. Which method you use depends on your specific requirements.
3939

40-
## Deserialization
40+
## Deserialization {#schema-deserialization}
4141

4242
JsonSchema.Net schemas are fully serializable.
4343

@@ -53,7 +53,7 @@ var mySchema = JsonSerializer.Deserialize<JsonSchema>(content);
5353

5454
Done.
5555

56-
## Inline
56+
## Inline {#schema-inlining}
5757

5858
There are many reasons why you would want to hard-code your schemas. This library actually hard-codes all of the meta-schemas. Whatever your reason, the `JsonSchemaBuilder` class is going to be your friend.
5959

@@ -70,7 +70,7 @@ var schema = builder.Build();
7070

7171
Let's take a look at some of the builder extension methods.
7272

73-
### Easy mode
73+
### Easy mode {#schema-how-to-1}
7474

7575
Some of the more straightforward builder methods are for like the `title` and `$comment` keywords, which just take a string:
7676

@@ -81,7 +81,7 @@ builder.Comment("a comment")
8181

8282
Notice that these methods implement a fluent interface so that you can chain them together.
8383

84-
### A little spice
84+
### A little spice {#schema-how-to-2}
8585

8686
Other extension methods can take multiple values. These have been overloaded to accept both `IEnumerable<T>` and `params` arrays just to keep things flexible.
8787

@@ -96,7 +96,7 @@ or just
9696
builder.Required("prop1", "prop2");
9797
```
9898

99-
### Now you're cooking with gas
99+
### Now you're cooking with gas {#schema-how-to-3}
100100

101101
Lastly, we have the extension methods which take advantage of C# 7 tuples. These include keywords like `$defs` and `properties` which take objects to mimic their JSON form.
102102

@@ -115,7 +115,7 @@ builder.Properties(
115115

116116
Did you notice how the `JsonSchemaBuilder` is just included directly without the `.Build()` method? These methods actually require `JsonSchema` objects. This leads us into the next part.
117117

118-
### Conversions
118+
### Conversions {#schema-implicit-cast}
119119

120120
`JsonSchemaBuilder` defines an implicit cast to `JsonSchema` which calls the `.Build()` method.
121121

@@ -156,11 +156,11 @@ builder.Properties(
156156
.AdditionalProperties(false);
157157
```
158158

159-
# Evaluation & annotations
159+
# Evaluation & annotations {#schema-evaluation}
160160

161161
***NOTE** In recognizing the multitude of uses for JSON Schema, the team has started to use the word "evaluate" instead of "validate" for the general processing of a schema. What was "validate" in v3.x of this library is now "evaluate" in order to align with this viewpoint.*
162162

163-
## Evaluating instances
163+
## Evaluating instances {#schema-evaluation-2}
164164

165165
`JsonSchema` exposes an `Evaluate()` method which is used to evaluate JSON instances. Let's begin with the following schema and a few JSON objects:
166166

@@ -224,7 +224,7 @@ In the above example, the following would result:
224224

225225
No errors would actually be reported here because the output format defaults to a "flag" format, which is a basic pass/fail. To get specific errors, the output format will need to be configured.
226226

227-
## Evaluation results
227+
## Evaluation results {#schema-results}
228228

229229
JSON Schema draft 2019-09 began the process to standardize the format for evaluation output in order to support cross-platform and cross-implementation compatibility. The format has been updated for the upcoming release to be more concise and clear. This includes support for both errors and annotation collection.
230230

@@ -240,7 +240,7 @@ The default output format is Flag, but this can be configured via the `Evaluatio
240240

241241
***NOTE** It's only possible to translate from a more detailed to a less detailed format.*
242242

243-
### Examples of output
243+
### Examples of output {#schema-output}
244244

245245
<details>
246246
<summary>Hierarchical</summary>
@@ -377,7 +377,7 @@ The default output format is Flag, but this can be configured via the `Evaluatio
377377

378378
</details>
379379

380-
## Value format validation
380+
## Value format validation {#schema-format}
381381

382382
The `format` keyword has been around a while. It's available in all of the versions supported by JsonSchema.Net. Although this keyword is technically classified as an annotation, the specification does allow (the word used is "SHOULD") that implementation provide some level of validation on it so long as that validation may be configured on and off.
383383

@@ -405,7 +405,7 @@ New formats must be registered via the `Formats.Register()` static method. This
405405

406406
***IMPORTANT** Format implementations MUST not contain state as the same instance will be shared by all of the schema instances that use it.
407407

408-
## Options
408+
## Options {#schema-options}
409409

410410
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.
411411

@@ -416,11 +416,11 @@ The `EvaluationOptions` class gives you a few configuration points for customizi
416416

417417
_\* 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._
418418

419-
# Managing references (`$ref`)
419+
# Managing references (`$ref`) {#schema-ref}
420420

421421
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.
422422

423-
## Schema resolution
423+
## Schema resolution {#schema-ref-resolution}
424424

425425
In order to resolve references more quickly, JsonSchema.Net maintains two registries for all schemas and identifiable subschemas that it has encountered. The first is a global registry, and the second is a local registry that is passed around on the evaluation context. If a schema is not found in the local registry, it will automatically fall back to the global registry.
426426

@@ -462,7 +462,7 @@ SchemaRegistry.Global.Register("http://localhost/random-string", randomString);
462462

463463
Now JsonSchema.Net will be able to resolve the reference.
464464

465-
## Resolving embedded schemas
465+
## Resolving embedded schemas {#schema-embedded-schemas}
466466

467467
In addition to schemas, other identifiable documents can be registered. For example, Open API documents _contain_ schemas but are not themselves schemas. Additionally, references between schemas within these documents are relative to the document root. Registering the Open API document will allow these references to be resolved.
468468

@@ -486,17 +486,17 @@ var schema = new JsonSchemaBuilder()
486486

487487
With the JSON document registered, the reference can resolve properly.
488488

489-
## Automatic resolution
489+
## Automatic resolution {#schema-ref-fetch}
490490

491491
In order to support scenarios where schemas cannot be registered ahead of time, the `SchemaRegistry` class exposes the `Fetch` property which is defined as `Func<Uri, JsonSchema>`. This property can be set to a method which downloads the content from the supplied URI and deserializes it into a `JsonSchema` object.
492492

493493
The URI that is passed may need to be transformed, based on the schemas you're dealing with. For instance if you're loading schemas from a local filesystem, and the schema `$ref`s use relative paths, you may need to prepend the working folder to the URI in order to locate it.
494494

495-
# Customizing error messages
495+
# Customizing error messages {#schema-errors}
496496

497497
The library exposes the `ErrorMessages` static type which includes read/write properties for all of the error messages. Customization of error messages can be achieved by setting these properties.
498498

499-
## Templates
499+
## Templates {#schema-error-templates}
500500

501501
Most of the error messages support token replacement. Tokens will use the format `[[foo]]` and will be replaced by the JSON serialization of the associated value.
502502

@@ -514,7 +514,7 @@ In this case, `[[received]]` will be replaced by the value in the JSON instance,
514514

515515
***NOTE** Since this example uses numbers, they appear without any particular formatting as this is how numbers serialize into JSON. Similarly, strings will render surrounded by double quotes, `true`, `false`, and `null` will appear using those literals, and more complex values like object and arrays will be rendered in their JSON representation.*
516516

517-
## Localization
517+
## Localization {#schema-error-localization}
518518

519519
In addition to customization, using resource files enables support for localization. The default locale is determined by `CultureInfo.CurrentCulture` and can be overridden by setting the `ErrorMessages.Culture` static property.
520520

json-everything.net/wwwroot/md/schema-datagen.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generation Sample JSON Data from a Schema
1+
# Generation Sample JSON Data from a Schema {#schema-datagen}
22

33
JsonSchema.Net.DataGeneration is a tool that can create JSON data instances using a JSON schema as a framework.
44

@@ -23,7 +23,7 @@ it can generate a JSON document like
2323

2424
Under the covers, the library uses the fabulous [Bogus](https://github.com/bchavez/Bogus) library, which is commonly used to generate random test data, and a few other tricks.
2525

26-
## Capabilities
26+
## Capabilities {#schema-datagen-capabilities}
2727

2828
This library is quite powerful. It supports most JSON Schema keywords, including `if`/`then`/`else` and aggregation keywords (`oneOf`, `allOf`, etc.).
2929

@@ -39,15 +39,15 @@ It currently does not support:
3939

4040
Everything else _should_ be mostly supported. Feel free to [open an issue](https://github.com/gregsdennis/json-everything/issues/new/choose) if you find something isn't working as you expect.
4141

42-
### Strings & `format`
42+
### Strings & `format` {#schema-datagen-strings}
4343

4444
All of the formats listed in the draft 2020-12 specification are supported, at least to the extent that they can be validated by JsonSchema.Net.
4545

4646
If a format is specified, it will be used.
4747

4848
If a format is not specified, Bogus's Lorem Ipsum generator is used to create some nice (but oddly readable) garbage text.
4949

50-
### Numerics
50+
### Numerics {#schema-datagen-numbers}
5151

5252
Integer and number generation each have custom algorithms that produce values that align with minimums, maximums, multiples, and even anti-multiples (numbers that should _not_ be divisors).
5353

@@ -81,7 +81,7 @@ the only valid integers are
8181

8282
The library will generate such values with ease.
8383

84-
### Arrays & Objects
84+
### Arrays & Objects {#schema-datagen-structured}
8585

8686
Care needs to be taken when specifying arrays that can have additional items or objects that can have additional properties. This library will unsubtly create moderatly deep trees of data if allowed.
8787

@@ -100,7 +100,7 @@ To combat this, there are some built-in limitations:
100100
- Item and property counts default to 0-10.
101101
- Arrays and objects have a lower chance of generating than the simpler types (null, integer, number, string).
102102

103-
# Generating Data
103+
# Generating Data {#schema-datagen-generation}
104104

105105
All you need to generate data is a schema object. This can be built inline or read in from an external source. The instructions for that are on the "Overview" tab.
106106

@@ -119,7 +119,7 @@ The result object has several properties:
119119
- `ErrorMessage` holds any error message, if unsuccessful
120120
- `InnerResults` holds result objects from nested generations. This can be useful for debugging.
121121

122-
# Summary
122+
# Summary {#schema-datagen-summary}
123123

124124
So, uh, yeah. I guess that's it really.
125125

0 commit comments

Comments
 (0)