From b998ce6e77a6b8e75b67b8a3d699266f79e62653 Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Thu, 21 Mar 2024 22:40:43 +0900 Subject: [PATCH] chore: Change JsonSchema EvaluationOptions instance to shared object (#9807) chore: change JsonSchema EvaluationOptions to shared object --- .../Validators/SchemaValidator.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Docfx.Build.SchemaDriven/Validators/SchemaValidator.cs b/src/Docfx.Build.SchemaDriven/Validators/SchemaValidator.cs index cc1d21a0f68..39af31df8ca 100644 --- a/src/Docfx.Build.SchemaDriven/Validators/SchemaValidator.cs +++ b/src/Docfx.Build.SchemaDriven/Validators/SchemaValidator.cs @@ -11,6 +11,12 @@ public class SchemaValidator { private readonly JsonSchema _schema; + private static readonly EvaluationOptions DefaultOptions = new EvaluationOptions + { + ValidateAgainstMetaSchema = false, + OutputFormat = OutputFormat.List, + }; + static SchemaValidator() { SchemaRegistry.Global.Register(new("http://dotnet.github.io/docfx/schemas/v1.0/schema.json#"), MetaSchemas.Draft7); @@ -25,11 +31,7 @@ public SchemaValidator(string json) public void Validate(object obj) { var json = JsonSerializer.Serialize(obj); - var result = _schema.Evaluate(JsonDocument.Parse(json), new EvaluationOptions - { - ValidateAgainstMetaSchema = false, - OutputFormat = OutputFormat.List, - }); + var result = _schema.Evaluate(JsonDocument.Parse(json), DefaultOptions); if (result.IsValid) return;