Skip to content

V10.1.0/minimal api support#26

Merged
gimlichael merged 6 commits into
mainfrom
v10.1.0/minimal-api-support
Feb 28, 2026
Merged

V10.1.0/minimal api support#26
gimlichael merged 6 commits into
mainfrom
v10.1.0/minimal-api-support

Conversation

@gimlichael

@gimlichael gimlichael commented Feb 28, 2026

Copy link
Copy Markdown
Member

This pull request introduces a minor release (10.1.0) focused on improving minimal API formatter integration and tightening option registration for ASP.NET Core formatter setup. It adds a new extension method for minimal configuration, ensures option registrations are not duplicated, and updates dependencies. The changes are documented and thoroughly tested.

New Features and Improvements

  • Added a new ServiceCollectionExtensions class in the Codebelt.Extensions.AspNetCore.Newtonsoft.Json namespace, providing the AddMinimalNewtonsoftJsonOptions method to simplify minimal API formatter setup. [1] [2] [3]
  • Updated the AddNewtonsoftJsonFormatterOptions method in ServiceCollectionExtensions (Formatters) to use TryConfigure, preventing duplicate option registrations and improving robustness when called multiple times. [1] [2]

Dependency and Version Updates

  • Upgraded the DocFX build image from version 2.78.4 to 2.78.5 in .docfx/Dockerfile.docfx.
  • Bumped package versions to 10.1.0 and updated release notes across all relevant PackageReleaseNotes.txt files, documenting new features and improvements. [1] [2] [3] [4]

Testing Enhancements

  • Added comprehensive unit tests for both the new AddMinimalNewtonsoftJsonOptions method and the improved formatter options registration, ensuring correct behavior, error handling, and prevention of duplicate registrations. [1] [2]

Documentation

  • Updated CHANGELOG.md to reflect new features, changes, and fixes in version 10.1.0.

Summary by CodeRabbit

  • New Features

    • Added AddMinimalNewtonsoftJsonOptions extension method for streamlined Newtonsoft JSON formatter configuration in ASP.NET Core.
  • Bug Fixes

    • Prevented duplicate IConfigureOptions registrations when formatter option methods are invoked repeatedly.
  • Chores

    • Bumped package versions to 10.1.0.
    • Updated build dependencies and release documentation.

@gimlichael gimlichael self-assigned this Feb 28, 2026
Copilot AI review requested due to automatic review settings February 28, 2026 03:01
@coderabbitai

coderabbitai Bot commented Feb 28, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR updates the Codebelt.Extensions.AspNetCore.Newtonsoft.Json package from version 10.0.4 to 10.1.0, introducing a new streamlined extension method AddMinimalNewtonsoftJsonOptions, modifying existing formatter option registration to use TryConfigure to prevent duplicates, and updating documentation and release notes accordingly.

Changes

Cohort / File(s) Summary
Docker Configuration
.docfx/Dockerfile.docfx
Updated base build image tag from codebeltnet/docfx:2.78.4 to codebeltnet/docfx:2.78.5.
Package Release Notes
.nuget/Codebelt.Extensions.AspNetCore.Mvc.Formatters.Newtonsoft.Json/PackageReleaseNotes.txt, .nuget/Codebelt.Extensions.AspNetCore.Newtonsoft.Json/PackageReleaseNotes.txt, .nuget/Codebelt.Extensions.Newtonsoft.Json.App/PackageReleaseNotes.txt, .nuget/Codebelt.Extensions.Newtonsoft.Json/PackageReleaseNotes.txt
Version bumped from 10.0.4 to 10.1.0; release notes formatting reformatted with adjusted headers and bullet-list styling.
Documentation
CHANGELOG.md
Added [10.1.0] release section with notes on new AddMinimalNewtonsoftJsonOptions method, modified TryConfigure behavior in formatter options, and duplicate registration prevention.
Core Functionality
src/Codebelt.Extensions.AspNetCore.Newtonsoft.Json/ServiceCollectionExtensions.cs
New public static extension class with AddMinimalNewtonsoftJsonOptions method for streamlined minimal Newtonsoft JSON configuration in ASP.NET Core DI.
Formatter Options
src/Codebelt.Extensions.AspNetCore.Newtonsoft.Json/Formatters/ServiceCollectionExtensions.cs
Modified AddNewtonsoftJsonFormatterOptions to use TryConfigure instead of Configure, preventing duplicate option registrations when method is invoked repeatedly.
Unit Tests
test/Codebelt.Extensions.AspNetCore.Newtonsoft.Json.Tests/ServiceCollectionExtensionsTest.cs, test/Codebelt.Extensions.AspNetCore.Newtonsoft.Json.Tests/Formatters/ServiceCollectionExtensionsTest.cs
Added comprehensive test coverage for new AddMinimalNewtonsoftJsonOptions method (null validation, return value, formatter registration, options configuration) and enhanced tests for formatter options registration behavior including duplicate-call scenarios.

Possibly related PRs

  • codebeltnet/newtonsoft-json\V9.0.0/depedency bump #3: Directly related—both PRs modify ServiceCollectionExtensions, add corresponding unit tests, and make related dependency/project changes in the same area.

Poem

🐰 A new method hops into view,
TryConfigure keeps duplicates at bay,
Minimal options, freshly made anew,
Version 10.1.0 leads the way!
No more registrations in dismay!

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'V10.1.0/minimal api support' directly aligns with the PR's primary objective of implementing a 10.1.0 minor release with minimal API formatter integration improvements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch v10.1.0/minimal-api-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
test/Codebelt.Extensions.AspNetCore.Newtonsoft.Json.Tests/Formatters/ServiceCollectionExtensionsTest.cs (1)

347-356: Strengthen idempotency test with behavioral assertion.

You assert single IConfigureOptions registration, but it would be safer to also assert the effective option value after both calls.

♻️ Proposed test hardening
 [Fact]
 public void AddNewtonsoftJsonFormatterOptions_ShouldOnlyRegisterOnce_WhenCalledMultipleTimes()
 {
     var services = new ServiceCollection();
     services.AddNewtonsoftJsonFormatterOptions(o => o.SensitivityDetails = FaultSensitivityDetails.All);
     services.AddNewtonsoftJsonFormatterOptions(o => o.SensitivityDetails = FaultSensitivityDetails.Evidence);

     var count = services.Count(s => s.ServiceType == typeof(IConfigureOptions<NewtonsoftJsonFormatterOptions>));
+    using var sp = services.BuildServiceProvider();
+    var options = sp.GetRequiredService<IOptions<NewtonsoftJsonFormatterOptions>>();

     Assert.Equal(1, count);
+    Assert.Equal(FaultSensitivityDetails.All, options.Value.SensitivityDetails);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@test/Codebelt.Extensions.AspNetCore.Newtonsoft.Json.Tests/Formatters/ServiceCollectionExtensionsTest.cs`
around lines 347 - 356, The test currently only checks registration count;
strengthen it by building the ServiceProvider from the ServiceCollection and
resolving IOptions<NewtonsoftJsonFormatterOptions> to assert the effective value
reflects the last call. Specifically, after the two
AddNewtonsoftJsonFormatterOptions calls in
AddNewtonsoftJsonFormatterOptions_ShouldOnlyRegisterOnce_WhenCalledMultipleTimes,
call services.BuildServiceProvider(), resolve
IOptions<NewtonsoftJsonFormatterOptions> (via GetRequiredService or GetService)
and Assert that Value.SensitivityDetails equals FaultSensitivityDetails.Evidence
to confirm the second registration wins.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@test/Codebelt.Extensions.AspNetCore.Newtonsoft.Json.Tests/Formatters/ServiceCollectionExtensionsTest.cs`:
- Around line 347-356: The test currently only checks registration count;
strengthen it by building the ServiceProvider from the ServiceCollection and
resolving IOptions<NewtonsoftJsonFormatterOptions> to assert the effective value
reflects the last call. Specifically, after the two
AddNewtonsoftJsonFormatterOptions calls in
AddNewtonsoftJsonFormatterOptions_ShouldOnlyRegisterOnce_WhenCalledMultipleTimes,
call services.BuildServiceProvider(), resolve
IOptions<NewtonsoftJsonFormatterOptions> (via GetRequiredService or GetService)
and Assert that Value.SensitivityDetails equals FaultSensitivityDetails.Evidence
to confirm the second registration wins.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between af01b09 and 7c75c5c.

📒 Files selected for processing (10)
  • .docfx/Dockerfile.docfx
  • .nuget/Codebelt.Extensions.AspNetCore.Mvc.Formatters.Newtonsoft.Json/PackageReleaseNotes.txt
  • .nuget/Codebelt.Extensions.AspNetCore.Newtonsoft.Json/PackageReleaseNotes.txt
  • .nuget/Codebelt.Extensions.Newtonsoft.Json.App/PackageReleaseNotes.txt
  • .nuget/Codebelt.Extensions.Newtonsoft.Json/PackageReleaseNotes.txt
  • CHANGELOG.md
  • src/Codebelt.Extensions.AspNetCore.Newtonsoft.Json/Formatters/ServiceCollectionExtensions.cs
  • src/Codebelt.Extensions.AspNetCore.Newtonsoft.Json/ServiceCollectionExtensions.cs
  • test/Codebelt.Extensions.AspNetCore.Newtonsoft.Json.Tests/Formatters/ServiceCollectionExtensionsTest.cs
  • test/Codebelt.Extensions.AspNetCore.Newtonsoft.Json.Tests/ServiceCollectionExtensionsTest.cs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR bumps the repo to version 10.1.0, adds a minimal-API-friendly DI extension for Newtonsoft.Json formatter integration, and makes formatter option registration idempotent to avoid duplicated IConfigureOptions<T> registrations.

Changes:

  • Added AddMinimalNewtonsoftJsonOptions to simplify minimal API registration (delegates to the existing exception response formatter registration).
  • Updated AddNewtonsoftJsonFormatterOptions to use TryConfigure to prevent duplicate option registrations.
  • Updated changelog/release notes and bumped the DocFX build image version.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/Codebelt.Extensions.AspNetCore.Newtonsoft.Json.Tests/ServiceCollectionExtensionsTest.cs New unit tests for AddMinimalNewtonsoftJsonOptions.
test/Codebelt.Extensions.AspNetCore.Newtonsoft.Json.Tests/Formatters/ServiceCollectionExtensionsTest.cs Added unit tests for AddNewtonsoftJsonFormatterOptions idempotent registration and formatter registration.
src/Codebelt.Extensions.AspNetCore.Newtonsoft.Json/ServiceCollectionExtensions.cs New minimal API-oriented service collection extension method.
src/Codebelt.Extensions.AspNetCore.Newtonsoft.Json/Formatters/ServiceCollectionExtensions.cs Switched options registration to TryConfigure to avoid duplicates.
CHANGELOG.md Added 10.1.0 entry describing the new method and TryConfigure change.
.nuget/Codebelt.Extensions.Newtonsoft.Json/PackageReleaseNotes.txt Bumped release notes version to 10.1.0.
.nuget/Codebelt.Extensions.Newtonsoft.Json.App/PackageReleaseNotes.txt Bumped release notes version to 10.1.0.
.nuget/Codebelt.Extensions.AspNetCore.Newtonsoft.Json/PackageReleaseNotes.txt Bumped release notes version to 10.1.0 and documented new feature/improvement.
.nuget/Codebelt.Extensions.AspNetCore.Mvc.Formatters.Newtonsoft.Json/PackageReleaseNotes.txt Bumped release notes version to 10.1.0.
.docfx/Dockerfile.docfx Updated DocFX image tag from 2.78.4 to 2.78.5.
Comments suppressed due to low confidence (1)

src/Codebelt.Extensions.AspNetCore.Newtonsoft.Json/Formatters/ServiceCollectionExtensions.cs:48

  • Switching to TryConfigure makes AddNewtonsoftJsonFormatterOptions effectively "first call wins"; subsequent calls with a different setup delegate will be ignored. The current XML docs don't mention this behavioral constraint, which can surprise callers that expect later registrations to override earlier ones. Consider documenting this explicitly (e.g., in a <remarks> block) or using an alternative that merges/overrides intentionally (such as PostConfigure) if overriding is desired.
        /// <summary>
        /// Adds configuration of <see cref="NewtonsoftJsonFormatterOptions"/> for the application.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/> to extend.</param>
        /// <param name="setup">The <see cref="NewtonsoftJsonFormatterOptions"/> which may be configured.</param>
        /// <returns>A reference to <paramref name="services" /> so that additional configuration calls can be chained.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="services"/> cannot be null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="setup"/> failed to configure an instance of <see cref="NewtonsoftJsonFormatterOptions"/> in a valid state.
        /// </exception>
        public static IServiceCollection AddNewtonsoftJsonFormatterOptions(this IServiceCollection services, Action<NewtonsoftJsonFormatterOptions> setup = null)
        {
            Validator.ThrowIfNull(services);
            Validator.ThrowIfInvalidConfigurator(setup, out var options);
            services.TryConfigure(setup ?? (o =>
            {
                o.Settings = options.Settings;
                o.SensitivityDetails = options.SensitivityDetails;
                o.SupportedMediaTypes = options.SupportedMediaTypes;
                o.SynchronizeWithJsonConvert = options.SynchronizeWithJsonConvert;
            }));
            return services;

Comment on lines +14 to +27
/// <summary>
/// Adds a <see cref="NewtonsoftJsonFormatterOptions"/> service to the specified <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add services to.</param>
/// <param name="setup">The <see cref="NewtonsoftJsonFormatterOptions"/> which may be configured.</param>
/// <returns>An <see cref="IServiceCollection"/> that can be used to further configure other services.</returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="services"/> cannot be null.
/// </exception>
public static IServiceCollection AddMinimalNewtonsoftJsonOptions(this IServiceCollection services, Action<NewtonsoftJsonFormatterOptions> setup = null)
{
Validator.ThrowIfNull(services);
return services.AddNewtonsoftJsonExceptionResponseFormatter(setup);
}

Copilot AI Feb 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The XML docs for AddMinimalNewtonsoftJsonOptions say it "Adds a NewtonsoftJsonFormatterOptions service", but the implementation delegates to AddNewtonsoftJsonExceptionResponseFormatter, which also registers an HttpExceptionDescriptorResponseFormatter<NewtonsoftJsonFormatterOptions>. Please update the summary/remarks (or rename the method) so the documentation matches the actual behavior (options + exception response formatter registration).

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback


# New Features
- ADDED ServiceCollectionExtensions class in the Codebelt.Extensions.AspNetCore.Newtonsoft.Json namespace with AddMinimalNewtonsoftJsonOptions method

Copilot AI Feb 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a non-breaking space / stray whitespace-only line between the new "# New Features" entry and the "# Improvements" section (line 9). This can render oddly in release tooling and makes diffs noisier; replace it with a normal blank line (standard space/newline) for consistent formatting.

Suggested change
 

Copilot uses AI. Check for mistakes.
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI commented Feb 28, 2026

Copy link
Copy Markdown

@gimlichael I've opened a new pull request, #27, to work on those changes. Once the pull request is ready, I'll request review from you.

@gimlichael gimlichael merged commit e80f81a into main Feb 28, 2026
25 checks passed
@gimlichael gimlichael deleted the v10.1.0/minimal-api-support branch February 28, 2026 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants