diff --git a/_framework/JsonSchema.Net.dll b/_framework/JsonSchema.Net.dll index 8701190..30491e1 100755 Binary files a/_framework/JsonSchema.Net.dll and b/_framework/JsonSchema.Net.dll differ diff --git a/_framework/JsonSchema.Net.dll.br b/_framework/JsonSchema.Net.dll.br index e16d9e9..da779cc 100644 Binary files a/_framework/JsonSchema.Net.dll.br and b/_framework/JsonSchema.Net.dll.br differ diff --git a/_framework/JsonSchema.Net.dll.gz b/_framework/JsonSchema.Net.dll.gz index 446e937..cbda85f 100644 Binary files a/_framework/JsonSchema.Net.dll.gz and b/_framework/JsonSchema.Net.dll.gz differ diff --git a/_framework/LearnJsonEverything.Template.dll b/_framework/LearnJsonEverything.Template.dll index 562839a..7b2dbd7 100644 Binary files a/_framework/LearnJsonEverything.Template.dll and b/_framework/LearnJsonEverything.Template.dll differ diff --git a/_framework/LearnJsonEverything.Template.dll.br b/_framework/LearnJsonEverything.Template.dll.br index 129106d..0705bb2 100644 Binary files a/_framework/LearnJsonEverything.Template.dll.br and b/_framework/LearnJsonEverything.Template.dll.br differ diff --git a/_framework/LearnJsonEverything.Template.dll.gz b/_framework/LearnJsonEverything.Template.dll.gz index 635cb0c..824becf 100644 Binary files a/_framework/LearnJsonEverything.Template.dll.gz and b/_framework/LearnJsonEverything.Template.dll.gz differ diff --git a/_framework/LearnJsonEverything.Template.pdb.gz b/_framework/LearnJsonEverything.Template.pdb.gz index 46dcd7c..374ee3c 100644 Binary files a/_framework/LearnJsonEverything.Template.pdb.gz and b/_framework/LearnJsonEverything.Template.pdb.gz differ diff --git a/_framework/LearnJsonEverything.dll b/_framework/LearnJsonEverything.dll index f9b197e..a08ba27 100644 Binary files a/_framework/LearnJsonEverything.dll and b/_framework/LearnJsonEverything.dll differ diff --git a/_framework/LearnJsonEverything.dll.br b/_framework/LearnJsonEverything.dll.br index c15dd66..669f452 100644 Binary files a/_framework/LearnJsonEverything.dll.br and b/_framework/LearnJsonEverything.dll.br differ diff --git a/_framework/LearnJsonEverything.dll.gz b/_framework/LearnJsonEverything.dll.gz index 07fb629..d4aedee 100644 Binary files a/_framework/LearnJsonEverything.dll.gz and b/_framework/LearnJsonEverything.dll.gz differ diff --git a/_framework/LearnJsonEverything.pdb.gz b/_framework/LearnJsonEverything.pdb.gz index 0815b1f..d8d49f8 100644 Binary files a/_framework/LearnJsonEverything.pdb.gz and b/_framework/LearnJsonEverything.pdb.gz differ diff --git a/_framework/blazor.boot.json b/_framework/blazor.boot.json index 46311a8..08b2ffa 100644 --- a/_framework/blazor.boot.json +++ b/_framework/blazor.boot.json @@ -1,7 +1,7 @@ { "mainAssemblyName": "LearnJsonEverything", "resources": { - "hash": "sha256-XQEBlVdk6yVtAkbCdg1EwvI2WZhJkfLiYNKG+TgmcYM=", + "hash": "sha256-TZGpgbg3hJhh5zf6OB4CasfrZd7Iv9mJXR1VTtt0Io0=", "jsModuleNative": { "dotnet.native.8.0.6.suuomc2hr0.js": "sha256-YU6M9+jtDVnB8/wtrgIndOstzNh778Ls8g9XnbjorSk=" }, @@ -23,9 +23,9 @@ "Humanizer.dll": "sha256-1oUwdVR9fjA+/WA1TZEaL/GO26WCzaL6WdkaLl3Pnpg=", "Json.More.dll": "sha256-xr0aE0+HsrvtjruJdaapKt2/DGB0qSUz+xD0XmvawxM=", "JsonPointer.Net.dll": "sha256-DzV9BEIGNC1mcOpb+JYI2gGXuDG5qg157LjFTnJ6pAE=", - "JsonSchema.Net.dll": "sha256-iCLcArFhOdHD16SQ2km8JXYsJmbv4fa37t+iopIb8+w=", - "LearnJsonEverything.dll": "sha256-Lq5CRgHpSk1hV8Ob/SG8cgXtzVVmHTKjHfF1yDc1ZuE=", - "LearnJsonEverything.Template.dll": "sha256-wVUdrrLmn7vzTG1UfmuFMFRgP7I1xk8Y1TH+gs+lePc=", + "JsonSchema.Net.dll": "sha256-fMEcBvXYh4ic/8yueXWxpfstkwPxuvnMxBURilBRSGs=", + "LearnJsonEverything.dll": "sha256-ae786toGXADOcdym3mpjsfFHDnPH8MMcD3HaKnBZ15I=", + "LearnJsonEverything.Template.dll": "sha256-EYCJ5QrMzhlkibGxWWDg1Pv9e6V4i0FTLwafqK8t2XE=", "Markdig.dll": "sha256-34Ry04hh+o21Q3VDOJoD0lmCasZYDBsC9CvOeWz3BjI=", "Markdig.SyntaxHighlighting.dll": "sha256-YEfO9OsS0T4kDjPXOW2pJF8qg62omn4UYMy/C2tcmC4=", "Microsoft.AspNetCore.Authorization.dll": "sha256-IsV1p8+7qyVgHgqn8Yon3RZfqKDNjdC/kTwzUwtaAlY=", diff --git a/_framework/blazor.boot.json.br b/_framework/blazor.boot.json.br index 27ce23a..517db3f 100644 Binary files a/_framework/blazor.boot.json.br and b/_framework/blazor.boot.json.br differ diff --git a/_framework/blazor.boot.json.gz b/_framework/blazor.boot.json.gz index 0c56da3..2b0dcc6 100644 Binary files a/_framework/blazor.boot.json.gz and b/_framework/blazor.boot.json.gz differ diff --git a/data/lessons/schema.yaml b/data/lessons/schema.yaml index fbe8b98..90b223c 100644 --- a/data/lessons/schema.yaml +++ b/data/lessons/schema.yaml @@ -336,3 +336,101 @@ - instance: 6.8 format: date-time isValid: false +- id: 26b6ebca-58e6-4814-8dea-4946d444c9a8 + background: | + _JsonSchema.Net_ supports every version of JSON Schema from Draft 6 forward. + + Version selection can be key to figuring out how to evaluate a schema. Generally, + the version will be determined by the meta-schema, as declared by the `$schema` + keyword. However, when `$schema` is absent, it's up to the tool and user to + decide. + + To set the JSON Schema version to use, you'll need to set the `EvaluateAs` property + on the evaluation options. + + This setting will have no effect if the schema _does_ have `$schema`. + + Lastly, this property is init-only, so you'll need to set it when creating the + options object. + + \* _This lesson works by taking advantage of the fact that JSON Schema ignores unknown + keywords. So when it evaluates a schema as Draft 6 that contains keywords from + Draft 7, the Draft 7 keywords aren't processed._ + docs: 'schema/basics/#schema-options' + title: 'Options: JSON Schema Version' + instructions: | + Create and configure an evaluation options object, and set the JSON Schema version + found in the `schemaVersion` variable. + inputTemplate: '' + contextCode: |- + using System; + using System.Collections.Generic; + using System.Text.Json; + using System.Text.Json.Nodes; + using System.Text.Json.Serialization; + using Json.Schema; + using Json.More; + + namespace LearnJsonEverything; + + public class Lesson : ILessonRunner + { + public EvaluationResults Run(JsonObject test) + { + var instance = test["instance"]; + var specVersion = test["version"].Deserialize( + new JsonSerializerOptions + { + Converters = { new EnumStringConverter() } + } + ); + + JsonSchema schema = new JsonSchemaBuilder() + .Type(SchemaValueType.Array) + .Items(new JsonSchemaBuilder() + .Type(SchemaValueType.Integer) + ) + .Contains(new JsonSchemaBuilder().Const(4)) + // Introduced with Draft 7 + .If(new JsonSchemaBuilder().MinItems(3)) + .Then(new JsonSchemaBuilder() + .Items(new JsonSchemaBuilder().MultipleOf(2)) + ) + // Introduced with Draft 2019-09 + .MinContains(2) + // Introduced with Draft 2020-12 + .PrefixItems( + new JsonSchemaBuilder().Type(SchemaValueType.String), + new JsonSchemaBuilder().Type(SchemaValueType.Boolean) + ); + + /* USER CODE */ + + return schema.Evaluate(instance, options); + } + } + tests: + - instance: [{},4] + version: Draft6 + isValid: false + - instance: [2,3,4,5] + version: Draft6 + isValid: true + - instance: [2,3,4,5] + version: Draft7 + isValid: false + - instance: [2,4,6,8] + version: Draft7 + isValid: true + - instance: [2,4,6,8] + version: Draft201909 + isValid: false + - instance: [2,4,6,8,4] + version: Draft201909 + isValid: true + - instance: [2,4,6,8,4] + version: Draft202012 + isValid: false + - instance: ["a string",true,2,4,6,8,4] + version: Draft202012 + isValid: true