Skip to content

Commit

Permalink
V9.0.0/net9rc1 support (#2)
Browse files Browse the repository at this point in the history
🚨 https://sonarcloud.io/organizations/geekle/rules?open=csharpsquid%3AS3343&rule_key=csharpsquid%3AS3343

⬆️ .net9 support

✨ support for failure/problemdetails

👷 updated CI to support .net9

💬 updated community health pages

📦 updated NuGet package definition

✅ fixed due to b10c3b7
  • Loading branch information
gimlichael authored Sep 22, 2024
1 parent 167ff67 commit f080206
Show file tree
Hide file tree
Showing 30 changed files with 305 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Complements: [Codebelt.Extensions.Newtonsoft.Json namespace](/api/extensions/jso

|Type|Ext|Methods|
|--:|:-:|---|
|JsonConverter|⬇️|`AddHttpExceptionDescriptorConverter`, `AddStringValuesConverter`|
|JsonConverter|⬇️|`AddHttpExceptionDescriptorConverter`, `AddStringValuesConverter`, `AddProblemDetailsConverter`|
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Complements: [Newtonsoft.Json.Converters namespace](https://www.newtonsoft.com/j

|Type|Ext|Methods|
|--:|:-:|---|
|JsonConverter|⬇️|`AddStringEnumConverter`, `AddStringFlagsEnumConverter`, `AddExceptionDescriptorConverterOf{T}`, `AddExceptionConverter`, `AddDataPairConverter`, `AddTransientFaultExceptionConverter`|
|JsonConverter|⬇️|`AddStringEnumConverter`, `AddStringFlagsEnumConverter`, `AddExceptionDescriptorConverterOf{T}`, `AddExceptionConverter`, `AddDataPairConverter`, `AddTransientFaultExceptionConverter`, `AddFailureConverter`|
2 changes: 1 addition & 1 deletion .github/workflows/pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
strategy:
matrix:
configuration: [Debug, Release]
framework: [net8.0,net6.0,netstandard2.0]
framework: [net9.0,net8.0,netstandard2.0]
outputs:
version: ${{ steps.minver-calculate.outputs.version }}
steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
Version 8.4.0
Version 9.0.0
Availability: .NET 9 and .NET 8

# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
- REMOVED Support for TFM .NET 6 (LTS)

# Breaking Changes
- REMOVED HttpExceptionDescriptorResponseHandlerExtensions class from the Codebelt.Extensions.AspNetCore.Mvc.Formatters.Newtonsoft.Json namespace

Version 8.4.0
Availability: .NET 8 and .NET 6

# ALM
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
Version 8.4.0
Version 9.0.0
Availability: .NET 9 and .NET 8

# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
- REMOVED Support for TFM .NET 6 (LTS)

# Improvements
- EXTENDED JsonConverterCollectionExtensions class in the Codebelt.Extensions.AspNetCore.Newtonsoft.Json.Converters namespace to include one new extension method: AddProblemDetailsConverter

Version 8.4.0
Availability: .NET 8 and .NET 6

# ALM
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
Version 8.4.0
Version 9.0.0
Availability: .NET 9 and .NET 8

# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
- REMOVED Support for TFM .NET 6 (LTS)

Version 8.4.0
Availability: .NET 8 and .NET 6

# ALM
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
Version 8.4.0
Version 9.0.0
Availability: .NET 9, .NET 8 and .NET Standard 2.0

# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
- REMOVED Support for TFM .NET 6 (LTS)

# New Features
- ADDED FailureConverter class in the Codebelt.Extensions.Newtonsoft.Json.Converters namespace to convert FailureConverter to JSON

# Improvements
- EXTENDED JsonConverterCollectionExtensions class in the Codebelt.Extensions.Newtonsoft.Json.Converters namespace to include one new extension method: AddFailureConverter

# Quality Analysis Actions
- CHANGED ValidatorExtensions class in the Codebelt.Extensions.Newtonsoft.Json namespace to be compliant with https://rules.sonarsource.com/csharp/type/Bug/RSPEC-3343/ (breaking change)

Version 8.4.0
Availability: .NET 8, .NET 6 and .NET Standard 2.0

# ALM
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ For more details, please refer to `PackageReleaseNotes.txt` on a per assembly ba

This major release is first and foremost focused on ironing out any wrinkles that have been introduced with .NET 9 preview releases so the final release is production ready together with the official launch from Microsoft.

### Added

- FailureConverter class in the Cuemon.Extensions.Newtonsoft.Json.Converters namespace to convert FailureConverter to JSON

### Changed

- JsonConverterCollectionExtensions class in the Cuemon.Extensions.AspNetCore.Newtonsoft.Json.Converters namespace was extended to include one new extension method: AddProblemDetailsConverter
- JsonConverterCollectionExtensions class in the Cuemon.Extensions.Newtonsoft.Json.Converters namespace was extended to include one new extension method: AddFailureConverter
- ValidatorExtensions class in the Codebelt.Extensions.Newtonsoft.Json namespace to be compliant with https://rules.sonarsource.com/csharp/type/Bug/RSPEC-3343/ (breaking change)

### Removed

- HttpExceptionDescriptorResponseHandlerExtensions class from the Cuemon.Extensions.AspNetCore.Mvc.Formatters.Newtonsoft.Json namespace (breaking change)

## [8.4.0] - 2024-09-22

### Dependencies
Expand Down
8 changes: 4 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'false'">
<TargetFrameworks>net8.0;net6.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0;netstandard2.0</TargetFrameworks>
<Copyright>Copyright © Geekle 2024. All rights reserved.</Copyright>
<Authors>gimlichael</Authors>
<Company>Geekle</Company>
Expand Down Expand Up @@ -49,11 +49,11 @@
</ItemGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true' AND '$(IsLinux)' == 'true'">
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true' AND '$(IsWindows)' == 'true'">
<TargetFrameworks>net8.0;net6.0;net48</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0;net48</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
Expand Down Expand Up @@ -81,7 +81,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Codebelt.Extensions.Xunit.App" Version="8.4.1" />
<PackageReference Include="Codebelt.Extensions.Xunit.App" Version="9.0.0-preview.2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<ProjectGuid>1c96ab07-1025-4551-91e0-5938ef86e585</ProjectGuid>
</PropertyGroup>

Expand All @@ -10,6 +10,10 @@
<PackageTags>extension-methods extensions json-converters add-json-serialization-formatters add-json-formatter-options</PackageTags>
</PropertyGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('net9'))">
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.0-rc.1.24452.1" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('net8'))">
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.8" />
</ItemGroup>
Expand All @@ -19,7 +23,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Cuemon.AspNetCore.Mvc" Version="8.3.2" />
<PackageReference Include="Cuemon.AspNetCore.Mvc" Version="9.0.0-preview.7" />
<PackageReference Include="Cuemon.Extensions.IO" Version="9.0.0-preview.7" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal static void Initialize()
NewtonsoftJsonFormatterOptions.DefaultConverters += list =>
{
list.AddStringValuesConverter();
list.AddProblemDetailsConverter();
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<ProjectGuid>ad0adf91-e7c7-4cb4-a39d-e1a5374c5602</ProjectGuid>
</PropertyGroup>

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

<ItemGroup>
<PackageReference Include="Cuemon.Extensions.AspNetCore" Version="8.3.2" />
<PackageReference Include="Cuemon.Extensions.AspNetCore" Version="9.0.0-preview.7" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Codebelt.Extensions.Newtonsoft.Json;
using Codebelt.Extensions.Newtonsoft.Json.Converters;
using Cuemon;
using Cuemon.AspNetCore.Diagnostics;
using Cuemon.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;

Expand All @@ -14,6 +17,60 @@ namespace Codebelt.Extensions.AspNetCore.Newtonsoft.Json.Converters
/// </summary>
public static class JsonConverterCollectionExtensions
{
/// <summary>
/// Adds a <see cref="ProblemDetails"/> JSON converter to the list.
/// </summary>
/// <param name="converters">The <see cref="T:ICollection{JsonConverter}" /> to extend.</param>
/// <returns>A reference to <paramref name="converters"/> after the operation has completed.</returns>
public static ICollection<JsonConverter> AddProblemDetailsConverter(this ICollection<JsonConverter> converters)
{
converters.Add(DynamicJsonConverter.Create<ProblemDetails>(WriteProblemDetails));
converters.Add(DynamicJsonConverter.Create<IDecorator<ProblemDetails>>((writer, dpd, serializer) => WriteProblemDetails(writer, dpd.Inner, serializer)));
return converters;
}

private static void WriteProblemDetails(JsonWriter writer, ProblemDetails pd, JsonSerializer serializer)
{
writer.WriteStartObject();
if (pd.Type != null)
{
writer.WritePropertyName(nameof(ProblemDetails.Type), serializer);
writer.WriteValue(pd.Type);
}

if (pd.Title != null)
{
writer.WritePropertyName(nameof(ProblemDetails.Title), serializer);
writer.WriteValue(pd.Title);
}

if (pd.Status.HasValue)
{
writer.WritePropertyName(nameof(ProblemDetails.Status), serializer);
writer.WriteValue(pd.Status.Value);
}

if (pd.Detail != null)
{
writer.WritePropertyName(nameof(ProblemDetails.Detail), serializer);
writer.WriteValue(pd.Detail);
}

if (pd.Instance != null)
{
writer.WritePropertyName(nameof(ProblemDetails.Instance), serializer);
writer.WriteValue(pd.Instance);
}

foreach (var extension in pd.Extensions.Where(kvp => kvp.Value != null))
{
writer.WritePropertyName(extension.Key, serializer);
writer.WriteObject(extension.Value, serializer);
}

writer.WriteEndObject();
}

/// <summary>
/// Adds an <see cref="HttpExceptionDescriptor"/> JSON converter to the list.
/// </summary>
Expand All @@ -24,6 +81,11 @@ public static ICollection<JsonConverter> AddHttpExceptionDescriptorConverter(thi
{
converters.AddExceptionDescriptorConverterOf<HttpExceptionDescriptor>(setup, (writer, descriptor, serializer) =>
{
if (descriptor.Instance != null)
{
JsonWriterExtensions.WritePropertyName(writer, "Instance", serializer);
writer.WriteValue(descriptor.Instance.OriginalString);
}
JsonWriterExtensions.WritePropertyName(writer, "Status", serializer);
writer.WriteValue(descriptor.StatusCode);
}, (writer, descriptor, serializer) =>
Expand All @@ -38,6 +100,11 @@ public static ICollection<JsonConverter> AddHttpExceptionDescriptorConverter(thi
JsonWriterExtensions.WritePropertyName(writer, "RequestId", serializer);
writer.WriteValue(descriptor.RequestId);
}
if (!string.IsNullOrWhiteSpace(descriptor.TraceId))
{
JsonWriterExtensions.WritePropertyName(writer, "TraceId", serializer);
writer.WriteValue(descriptor.TraceId);
}
});
return converters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Codebelt.Extensions.Newtonsoft.Json.Formatters;
using Cuemon;
using Cuemon.AspNetCore.Diagnostics;
using Cuemon.Extensions.DependencyInjection;
using Cuemon.Net.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
Expand Down Expand Up @@ -38,7 +37,7 @@ public static IServiceCollection AddNewtonsoftJsonFormatterOptions(this IService
{
Validator.ThrowIfNull(services);
Validator.ThrowIfInvalidConfigurator(setup, out var options);
services.TryConfigure(setup ?? (o =>
services.Configure(setup ?? (o =>
{
o.Settings = options.Settings;
o.SensitivityDetails = options.SensitivityDetails;
Expand All @@ -61,13 +60,14 @@ public static IServiceCollection AddNewtonsoftJsonFormatterOptions(this IService
public static IServiceCollection AddNewtonsoftJsonExceptionResponseFormatter(this IServiceCollection services, Action<NewtonsoftJsonFormatterOptions> setup = null)
{
Validator.ThrowIfNull(services);
services.AddNewtonsoftJsonFormatterOptions(setup);
AddNewtonsoftJsonFormatterOptions(services, setup);
services.TryAddSingleton(provider =>
{
var options = provider.GetService<IOptions<NewtonsoftJsonFormatterOptions>>().Value;
var faultDescriptorOptions = provider.GetRequiredService<IOptions<FaultDescriptorOptions>>().Value;
return new HttpExceptionDescriptorResponseFormatter<NewtonsoftJsonFormatterOptions>(options)
.Adjust(o => o.Settings.Converters.AddHttpExceptionDescriptorConverter(edo => edo.SensitivityDetails = o.SensitivityDetails))
.Populate((descriptor, contentType) => new StreamContent(NewtonsoftJsonFormatter.SerializeObject(descriptor, options))
.Populate((descriptor, contentType) => new StreamContent(NewtonsoftJsonFormatter.SerializeObject(faultDescriptorOptions.FaultDescriptor == PreferredFaultDescriptor.FaultDetails ? descriptor : Decorator.Enclose(descriptor).ToProblemDetails(options.SensitivityDetails), options))
{
Headers = { { HttpHeaderNames.ContentType, contentType.MediaType } }
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<ProjectGuid>a051b5d8-0986-4dea-b215-2e2b6068d125</ProjectGuid>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cuemon.Core" Version="8.3.2" />
<PackageReference Include="Cuemon.IO" Version="8.3.2" />
<PackageReference Include="Cuemon.Core" Version="9.0.0-preview.7" />
<PackageReference Include="Cuemon.IO" Version="9.0.0-preview.7" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

Expand Down
Loading

0 comments on commit f080206

Please sign in to comment.