diff --git a/.github/dependabot.yml b/.github/dependabot.yml index eb80fbb..84e52b8 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -12,3 +12,23 @@ updates: commit-message: include: scope prefix: "fix: " + # Framework-aligned packages are versioned per target framework in Directory.Packages.props. + # A new major version means a new target framework block, which is added by hand. + ignore: + - dependency-name: "Microsoft.Extensions.*" + update-types: ["version-update:semver-major"] + - dependency-name: "Microsoft.EntityFrameworkCore*" + update-types: ["version-update:semver-major"] + - dependency-name: "Microsoft.AspNetCore.Authentication.JwtBearer" + update-types: ["version-update:semver-major"] + - dependency-name: "Microsoft.AspNetCore.JsonPatch" + update-types: ["version-update:semver-major"] + - dependency-name: "Microsoft.AspNetCore.Mvc.NewtonsoftJson" + update-types: ["version-update:semver-major"] + - package-ecosystem: "dotnet-sdk" + directory: "/" + schedule: + interval: "monthly" + commit-message: + include: scope + prefix: "chore: " diff --git a/.github/workflows/dotnet-release.yml b/.github/workflows/dotnet-release.yml index 79888f2..3260af3 100644 --- a/.github/workflows/dotnet-release.yml +++ b/.github/workflows/dotnet-release.yml @@ -12,11 +12,18 @@ jobs: steps: - name: Setup Git - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: token : ${{ secrets.FIREBEND_GIT_PUSH_PAT}} fetch-depth: 0 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + # The .NET 9 SDK supplies the net9.0 runtime for tests; global.json pins the SDK that builds. + dotnet-version: 9.0.x + global-json-file: global.json + - name: Install Versionize run: dotnet tool install --global Versionize @@ -34,12 +41,6 @@ jobs: if: steps.versionize.outcome != 'success' run: echo "Skipping publishing. No release required." - - name: Setup .NET - if: steps.versionize.outcome == 'success' - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 8.0.101 - - name: Restore dependencies if: steps.versionize.outcome == 'success' run: dotnet restore json-patch-generator.sln diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index bc8f429..f7a26a3 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -12,12 +12,14 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup .NET - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.101 + # The .NET 9 SDK supplies the net9.0 runtime for tests; global.json pins the SDK that builds. + dotnet-version: 9.0.x + global-json-file: global.json - name: Restore dependencies run: dotnet restore json-patch-generator.sln diff --git a/.versionize b/.versionize index 77fa5f2..8458f60 100644 --- a/.versionize +++ b/.versionize @@ -1,6 +1,6 @@ { "changelog": { - "header": "Lit Redis Changelog", + "header": "Json Patch Generator Changelog", "includeAllCommits": true, "sections": [ { diff --git a/CHANGELOG.md b/CHANGELOG.md index 8645030..b372490 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -Lit Redis Changelog +Json Patch Generator Changelog ## [9.0.13](https://www.github.com/firebend/json-patch-generator/releases/tag/v9.0.13) (2025-09-17) diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..5db5b8c --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,15 @@ + + + + + net9.0;net10.0 + + net10.0 + + + + + + + + diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 0000000..469a2a3 --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,31 @@ + + + + true + + + + + + + + + + + + + + + + + + + + + + + diff --git a/README.md b/README.md index d029300..adfc2c6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # Firebend JSON Patch Generator -A class library for comparing objects and generating JSON patch documents. \ No newline at end of file +A class library for comparing objects and generating JSON patch documents. + +## Building from source + +- Building requires the .NET SDK version in [`global.json`](global.json) (10.0.401 or a later 10.0.4xx patch). Running the tests also needs the .NET 9 runtime. +- Target frameworks are set in [`Directory.Build.props`](Directory.Build.props). `FirebendTargetFrameworks` lists the frameworks every library and test project builds for (currently `net9.0;net10.0`). `FirebendAppTargetFramework` is the single framework for samples and other runnable apps. +- Package versions are managed centrally in [`Directory.Packages.props`](Directory.Packages.props). Microsoft framework packages have one version block per target framework, so adding a framework means adding it to `FirebendTargetFrameworks` and adding a matching block there. diff --git a/global.json b/global.json new file mode 100644 index 0000000..f3e8020 --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "10.0.401", + "rollForward": "latestPatch" + } +} diff --git a/nuget.config b/nuget.config new file mode 100644 index 0000000..1cff172 --- /dev/null +++ b/nuget.config @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/JsonPatchGenerator/DefaultJsonPatchGenerator.cs b/src/JsonPatchGenerator/DefaultJsonPatchGenerator.cs index bdf4e33..03e0f99 100644 --- a/src/JsonPatchGenerator/DefaultJsonPatchGenerator.cs +++ b/src/JsonPatchGenerator/DefaultJsonPatchGenerator.cs @@ -44,7 +44,10 @@ public JsonPatchDocument Generate(T original, T modified) var diffs = _diffDetector.DetectChanges(original, modified); - if (!diffs.Any()) { return new(); } + if (!diffs.Any()) + { + return new(); + } using var scope = _serviceProvider.CreateScope(); var writer = scope.ServiceProvider.GetRequiredService(); diff --git a/src/JsonPatchGenerator/Interfaces/IJsonDiffDetector.cs b/src/JsonPatchGenerator/Interfaces/IJsonDiffDetector.cs index 8124fed..e6e64bf 100644 --- a/src/JsonPatchGenerator/Interfaces/IJsonDiffDetector.cs +++ b/src/JsonPatchGenerator/Interfaces/IJsonDiffDetector.cs @@ -17,5 +17,5 @@ public interface IJsonDiffDetector /// /// A list of /// - List DetectChanges(object original, object modified); + public List DetectChanges(object original, object modified); } diff --git a/src/JsonPatchGenerator/Interfaces/IJsonDiffSettingsProvider.cs b/src/JsonPatchGenerator/Interfaces/IJsonDiffSettingsProvider.cs index df1d766..434027c 100644 --- a/src/JsonPatchGenerator/Interfaces/IJsonDiffSettingsProvider.cs +++ b/src/JsonPatchGenerator/Interfaces/IJsonDiffSettingsProvider.cs @@ -4,5 +4,5 @@ namespace Firebend.JsonPatch.Interfaces; public interface IJsonDiffSettingsProvider { - JsonSerializerSettings Get(); + public JsonSerializerSettings Get(); } diff --git a/src/JsonPatchGenerator/Interfaces/IJsonPatchGenerator.cs b/src/JsonPatchGenerator/Interfaces/IJsonPatchGenerator.cs index 810fd55..529aa51 100644 --- a/src/JsonPatchGenerator/Interfaces/IJsonPatchGenerator.cs +++ b/src/JsonPatchGenerator/Interfaces/IJsonPatchGenerator.cs @@ -20,7 +20,7 @@ public interface IJsonPatchGenerator /// /// A representing the changes in the two objects. /// - JsonPatchDocument Generate(T original, T modified) where T : class; + public JsonPatchDocument Generate(T original, T modified) where T : class; /// /// Converts a and converts it to the non-generic @@ -34,5 +34,5 @@ public interface IJsonPatchGenerator /// /// A /// - JsonPatchDocument ConvertFromGeneric(JsonPatchDocument patch) where T : class; + public JsonPatchDocument ConvertFromGeneric(JsonPatchDocument patch) where T : class; } diff --git a/src/JsonPatchGenerator/Interfaces/IJsonPatchWriter.cs b/src/JsonPatchGenerator/Interfaces/IJsonPatchWriter.cs index 0e861c1..60082c9 100644 --- a/src/JsonPatchGenerator/Interfaces/IJsonPatchWriter.cs +++ b/src/JsonPatchGenerator/Interfaces/IJsonPatchWriter.cs @@ -11,7 +11,7 @@ public interface IJsonPatchWriter /// /// The value added. /// - void WriteAdd(string path, object value); + public void WriteAdd(string path, object value); /// /// Writes a json patch replace operation to the output. @@ -22,7 +22,7 @@ public interface IJsonPatchWriter /// /// The value replaced. /// - void WriteReplace(string path, object value); + public void WriteReplace(string path, object value); /// /// Writes a json remove operation to the output @@ -30,7 +30,7 @@ public interface IJsonPatchWriter /// /// The json patch path /// - void WriteRemove(string path); + public void WriteRemove(string path); /// /// Finishes writing the json patch document and returns it as a string @@ -38,5 +38,5 @@ public interface IJsonPatchWriter /// /// A json patch in string form. /// - string Finish(); + public string Finish(); } diff --git a/src/JsonPatchGenerator/JsonDiffDetector.cs b/src/JsonPatchGenerator/JsonDiffDetector.cs index 51b21ff..81fc1e1 100644 --- a/src/JsonPatchGenerator/JsonDiffDetector.cs +++ b/src/JsonPatchGenerator/JsonDiffDetector.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using Firebend.JsonPatch.Extensions; @@ -10,16 +11,14 @@ namespace Firebend.JsonPatch; public class JsonDiffDetector : IJsonDiffDetector { - private readonly IJsonDiffSettingsProvider _settings; - - private JsonSerializer _serializer; + private readonly Lazy _serializer; public JsonDiffDetector(IJsonDiffSettingsProvider settings) { - _settings = settings; + _serializer = new Lazy(() => JsonSerializer.Create(settings.Get())); } - private JsonSerializer Serializer => _serializer ??= JsonSerializer.Create(_settings.Get()); + private JsonSerializer Serializer => _serializer.Value; public List DetectChanges(object original, object modified) => DetectChangesRecursion(GetJObject(original), GetJObject(modified), [], string.Empty); diff --git a/src/JsonPatchGenerator/JsonPatchGenerator.csproj b/src/JsonPatchGenerator/JsonPatchGenerator.csproj index e2fc531..70f6f9e 100644 --- a/src/JsonPatchGenerator/JsonPatchGenerator.csproj +++ b/src/JsonPatchGenerator/JsonPatchGenerator.csproj @@ -1,7 +1,7 @@ - netstandard2.1 + $(FirebendTargetFrameworks) 9.0.13 Firebend.JsonPatchGenerator Firebend.JsonPatch @@ -15,14 +15,14 @@ firebend;json;patch;document;jsonpatch; Firebend https://github.com/firebend/json-patch-generator - https://github.com/firebend/json-patch-generator/blob/main/LICENSE + MIT https://github.com/firebend/json-patch-generator - https://github.com/firebend/json-patch-generator/blob/main/nuget-image.png?raw=true + nuget-image.png - - + + diff --git a/tests/JsonPatchGenerator.Tests/JsonPatchGenerator.Tests.csproj b/tests/JsonPatchGenerator.Tests/JsonPatchGenerator.Tests.csproj index e8352ac..2e120d8 100644 --- a/tests/JsonPatchGenerator.Tests/JsonPatchGenerator.Tests.csproj +++ b/tests/JsonPatchGenerator.Tests/JsonPatchGenerator.Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + $(FirebendTargetFrameworks) false @@ -11,11 +11,11 @@ - - - - - + + + + + diff --git a/tests/JsonPatchGenerator.Tests/JsonPatchGeneratorTests.cs b/tests/JsonPatchGenerator.Tests/JsonPatchGeneratorTests.cs index c21ec7f..9bb1c8c 100644 --- a/tests/JsonPatchGenerator.Tests/JsonPatchGeneratorTests.cs +++ b/tests/JsonPatchGenerator.Tests/JsonPatchGeneratorTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Threading.Tasks; using Firebend.JsonPatch.Extensions; using Firebend.JsonPatch.Interfaces; using Firebend.JsonPatch.JsonSerializationSettings; @@ -12,7 +13,6 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Serialization; -using System.Threading.Tasks; // ReSharper disable UnusedAutoPropertyAccessor.Local