From db49b4c2c062c0ab6f258f5fe6e355d947157e83 Mon Sep 17 00:00:00 2001 From: Greg Dennis Date: Sat, 5 Aug 2023 16:13:02 +1200 Subject: [PATCH] add mechanism to fetch local schema --- JsonSchema/JsonSchema.csproj | 4 ++-- JsonSchema/SchemaConstraint.cs | 15 +++++++++++++++ .../release-notes/rn-json-schema.md | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/JsonSchema/JsonSchema.csproj b/JsonSchema/JsonSchema.csproj index 2f01eec1c8..0caa0f93cf 100644 --- a/JsonSchema/JsonSchema.csproj +++ b/JsonSchema/JsonSchema.csproj @@ -16,8 +16,8 @@ https://github.com/gregsdennis/json-everything https://github.com/gregsdennis/json-everything json-schema validation schema json - 5.1.0 - 5.1.0.0 + 5.1.1 + 5.1.1.0 5.0.0.0 LICENSE JsonSchema.Net diff --git a/JsonSchema/SchemaConstraint.cs b/JsonSchema/SchemaConstraint.cs index 1f2a106584..4e10029341 100644 --- a/JsonSchema/SchemaConstraint.cs +++ b/JsonSchema/SchemaConstraint.cs @@ -103,4 +103,19 @@ public SchemaEvaluation BuildEvaluation(JsonNode? localInstance, JsonPointer ins return evaluation; } + + /// + /// Gets the local schema object. + /// + /// Evaluation options. + /// The local object represented by this constraint. + /// + /// This method can lead to inefficiencies. It is provided as a last resort to access the schema directly. + /// + public JsonSchema GetLocalSchema(EvaluationOptions options) + { + var baseSchema = options.SchemaRegistry.Get(SchemaBaseUri); + + return baseSchema!.FindSubschema(BaseInstanceLocation, options)!; + } } \ No newline at end of file diff --git a/tools/ApiDocsGenerator/release-notes/rn-json-schema.md b/tools/ApiDocsGenerator/release-notes/rn-json-schema.md index 81904170e0..9a8ba03dd3 100644 --- a/tools/ApiDocsGenerator/release-notes/rn-json-schema.md +++ b/tools/ApiDocsGenerator/release-notes/rn-json-schema.md @@ -4,6 +4,10 @@ title: JsonSchema.Net icon: fas fa-tag order: "8.01" --- +# [5.1.1](commit) {#release-schema-5.1.1} + +Added `SchemaConstraint.GetLocalSchema()` for accessing the local schema. (To be used as a last resort, but may be necessary.) + # [5.1.0](https://github.com/gregsdennis/json-everything/pull/499) {#release-schema-5.1.0} [#493](https://github.com/gregsdennis/json-everything/issues/493) - Add support for reporting error messages in multiple cultures in parallel. Thanks to [@m-adamkiewicz](https://github.com/m-adamkiewicz) for the suggestion.