Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
15 changes: 8 additions & 7 deletions .github/workflows/dotnet-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .versionize
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"changelog": {
"header": "Lit Redis Changelog",
"header": "Json Patch Generator Changelog",
"includeAllCommits": true,
"sections": [
{
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Lit Redis Changelog
Json Patch Generator Changelog
<a name="9.0.13"></a>
## [9.0.13](https://www.github.com/firebend/json-patch-generator/releases/tag/v9.0.13) (2025-09-17)

Expand Down
15 changes: 15 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project>

<PropertyGroup>
<!-- Frameworks every packable library and test project targets. Edit this list to add or drop a framework. -->
<FirebendTargetFrameworks>net9.0;net10.0</FirebendTargetFrameworks>
<!-- Single framework for samples, benchmarks, and other runnable apps. -->
<FirebendAppTargetFramework>net10.0</FirebendAppTargetFramework>
</PropertyGroup>

<ItemGroup Condition="'$(PackageIcon)' != ''">
<!-- Embeds the repo-root icon in every package that sets PackageIcon. -->
<None Include="$(MSBuildThisFileDirectory)nuget-image.png" Pack="true" PackagePath="\" Visible="false" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project>

<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<!--
Framework-aligned packages ship a release line per .NET version, so each target framework
gets its own version. To add a framework (for example net11.0), copy one of these blocks,
change the condition, and set the matching 11.0.x versions.
-->
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageVersion Include="Microsoft.AspNetCore.JsonPatch" Version="9.0.20" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.20" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageVersion Include="Microsoft.AspNetCore.JsonPatch" Version="10.0.12" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.12" />
</ItemGroup>

<!-- Packages that are versioned independently of the .NET release. -->
<ItemGroup>
<!-- FluentAssertions v8 requires a commercial license; stay on the latest v7. -->
<PackageVersion Include="FluentAssertions" Version="7.2.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.10.1" />
<PackageVersion Include="MSTest.TestAdapter" Version="4.5.1" />
<PackageVersion Include="MSTest.TestFramework" Version="4.5.1" />
</ItemGroup>

</Project>
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# Firebend JSON Patch Generator
A class library for comparing objects and generating JSON patch documents.
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.
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "10.0.401",
"rollForward": "latestPatch"
}
}
13 changes: 13 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- Restore only from nuget.org so central package management resolves the same way on every machine. -->
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>
5 changes: 4 additions & 1 deletion src/JsonPatchGenerator/DefaultJsonPatchGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public JsonPatchDocument<T> Generate<T>(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<IJsonPatchWriter>();
Expand Down
2 changes: 1 addition & 1 deletion src/JsonPatchGenerator/Interfaces/IJsonDiffDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public interface IJsonDiffDetector
/// <returns>
/// A list of <see cref="JsonDiff"/>
/// </returns>
List<JsonDiff> DetectChanges(object original, object modified);
public List<JsonDiff> DetectChanges(object original, object modified);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace Firebend.JsonPatch.Interfaces;

public interface IJsonDiffSettingsProvider
{
JsonSerializerSettings Get();
public JsonSerializerSettings Get();
}
4 changes: 2 additions & 2 deletions src/JsonPatchGenerator/Interfaces/IJsonPatchGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface IJsonPatchGenerator
/// <returns>
/// A <see cref="JsonPatchDocument{TModel}"/> representing the changes in the two objects.
/// </returns>
JsonPatchDocument<T> Generate<T>(T original, T modified) where T : class;
public JsonPatchDocument<T> Generate<T>(T original, T modified) where T : class;

/// <summary>
/// Converts a <see cref="JsonPatchDocument{TModel}"/> and converts it to the non-generic <see cref="JsonPatchDocument"/>
Expand All @@ -34,5 +34,5 @@ public interface IJsonPatchGenerator
/// <returns>
/// A <see cref="JsonPatchDocument"/>
/// </returns>
JsonPatchDocument ConvertFromGeneric<T>(JsonPatchDocument<T> patch) where T : class;
public JsonPatchDocument ConvertFromGeneric<T>(JsonPatchDocument<T> patch) where T : class;
}
8 changes: 4 additions & 4 deletions src/JsonPatchGenerator/Interfaces/IJsonPatchWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IJsonPatchWriter
/// <param name="value">
/// The value added.
/// </param>
void WriteAdd(string path, object value);
public void WriteAdd(string path, object value);

/// <summary>
/// Writes a json patch replace operation to the output.
Expand All @@ -22,21 +22,21 @@ public interface IJsonPatchWriter
/// <param name="value">
/// The value replaced.
/// </param>
void WriteReplace(string path, object value);
public void WriteReplace(string path, object value);

/// <summary>
/// Writes a json remove operation to the output
/// </summary>
/// <param name="path">
/// The json patch path
/// </param>
void WriteRemove(string path);
public void WriteRemove(string path);

/// <summary>
/// Finishes writing the json patch document and returns it as a string
/// </summary>
/// <returns>
/// A json patch in string form.
/// </returns>
string Finish();
public string Finish();
}
9 changes: 4 additions & 5 deletions src/JsonPatchGenerator/JsonDiffDetector.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Firebend.JsonPatch.Extensions;
Expand All @@ -10,16 +11,14 @@ namespace Firebend.JsonPatch;

public class JsonDiffDetector : IJsonDiffDetector
{
private readonly IJsonDiffSettingsProvider _settings;

private JsonSerializer _serializer;
private readonly Lazy<JsonSerializer> _serializer;

public JsonDiffDetector(IJsonDiffSettingsProvider settings)
{
_settings = settings;
_serializer = new Lazy<JsonSerializer>(() => JsonSerializer.Create(settings.Get()));
}

private JsonSerializer Serializer => _serializer ??= JsonSerializer.Create(_settings.Get());
private JsonSerializer Serializer => _serializer.Value;

public List<JsonDiff> DetectChanges(object original, object modified)
=> DetectChangesRecursion(GetJObject(original), GetJObject(modified), [], string.Empty);
Expand Down
10 changes: 5 additions & 5 deletions src/JsonPatchGenerator/JsonPatchGenerator.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFrameworks>$(FirebendTargetFrameworks)</TargetFrameworks>
<Version>9.0.13</Version>
<AssemblyName>Firebend.JsonPatchGenerator</AssemblyName>
<RootNamespace>Firebend.JsonPatch</RootNamespace>
Expand All @@ -15,14 +15,14 @@
<PackageTags>firebend;json;patch;document;jsonpatch;</PackageTags>
<Authors>Firebend</Authors>
<RepositoryUrl>https://github.com/firebend/json-patch-generator</RepositoryUrl>
<PackageLicenseUrl>https://github.com/firebend/json-patch-generator/blob/main/LICENSE</PackageLicenseUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/firebend/json-patch-generator</PackageProjectUrl>
<PackageIconUrl>https://github.com/firebend/json-patch-generator/blob/main/nuget-image.png?raw=true</PackageIconUrl>
<PackageIcon>nuget-image.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="9.0.8" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.8" />
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
</ItemGroup>

</Project>
12 changes: 6 additions & 6 deletions tests/JsonPatchGenerator.Tests/JsonPatchGenerator.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>$(FirebendTargetFrameworks)</TargetFrameworks>

<IsPackable>false</IsPackable>

Expand All @@ -11,11 +11,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.10.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.10.0" />
<PackageReference Include="FluentAssertions" Version="8.6.0" />
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="9.0.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tests/JsonPatchGenerator.Tests/JsonPatchGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,7 +13,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using System.Threading.Tasks;

// ReSharper disable UnusedAutoPropertyAccessor.Local

Expand Down
Loading