Skip to content

Commit

Permalink
chore: Change JsonSchema EvaluationOptions instance to shared object (#…
Browse files Browse the repository at this point in the history
…9807)

chore: change JsonSchema EvaluationOptions to shared object
  • Loading branch information
filzrev authored Mar 21, 2024
1 parent 84a6540 commit b998ce6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Docfx.Build.SchemaDriven/Validators/SchemaValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit b998ce6

Please sign in to comment.