From 052f2521468886e75b99268ee372ac5ede4d8a3d Mon Sep 17 00:00:00 2001 From: erri120 Date: Sun, 7 Jul 2024 12:28:54 +0200 Subject: [PATCH] Replace Newtonsoft.Json.Schema with NJsonSchema --- build/deploy-local-smapi.targets | 2 +- src/SMAPI.Toolkit/SMAPI.Toolkit.csproj | 2 +- src/SMAPI.Toolkit/Serialization/JsonHelper.cs | 24 ++++--------------- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/build/deploy-local-smapi.targets b/build/deploy-local-smapi.targets index bc97dedf8..26c29af53 100644 --- a/build/deploy-local-smapi.targets +++ b/build/deploy-local-smapi.targets @@ -22,7 +22,7 @@ This assumes `find-game-folder.targets` has already been imported and validated. - + diff --git a/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj b/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj index 8871d9bdf..a861883bd 100644 --- a/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj +++ b/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/SMAPI.Toolkit/Serialization/JsonHelper.cs b/src/SMAPI.Toolkit/Serialization/JsonHelper.cs index a1ae915af..539ef344e 100644 --- a/src/SMAPI.Toolkit/Serialization/JsonHelper.cs +++ b/src/SMAPI.Toolkit/Serialization/JsonHelper.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.IO; using Newtonsoft.Json; using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Schema; -using Newtonsoft.Json.Schema.Generation; +using NJsonSchema; using StardewModdingAPI.Toolkit.Serialization.Converters; namespace StardewModdingAPI.Toolkit.Serialization @@ -13,20 +11,6 @@ namespace StardewModdingAPI.Toolkit.Serialization /// Encapsulates SMAPI's JSON file parsing. public class JsonHelper { - /********* - ** Fields - *********/ - /// The JSON schema generator to use when creating a schema file. - private readonly JSchemaGenerator SchemaGenerator = new(); - - /// The JSON settings to use when creating a schema file. - private readonly JSchemaWriterSettings SchemaWriterSettings = new() - { - Version = SchemaVersion.Draft2019_09, - ReferenceHandling = JSchemaWriterReferenceHandling.Never - }; - - /********* ** Accessors *********/ @@ -61,7 +45,7 @@ public static JsonSerializerSettings CreateDefaultSettings() /// The file contains invalid JSON. public bool ReadJsonFileIfExists(string fullPath, #if NET6_0_OR_GREATER - [NotNullWhen(true)] + [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] #endif out TModel? result ) @@ -142,8 +126,8 @@ public void WriteJsonSchemaFile(string fullPath) Directory.CreateDirectory(dir); // write file - JSchema schema = this.SchemaGenerator.Generate(typeof(TModel)); - string json = schema.ToString(this.SchemaWriterSettings); + JsonSchema schema = JsonSchema.FromType(); + string json = schema.ToJson(); File.WriteAllText(fullPath, json); }