From 49a281ead161535fcef4c8a7f6e999846dc64ec1 Mon Sep 17 00:00:00 2001 From: Marco Minerva Date: Wed, 10 Dec 2025 11:16:31 +0100 Subject: [PATCH 1/2] Update JWT version, OpenAPI docs, and code style settings - Set dotnet_style_require_accessibility_modifiers in .editorconfig - Remove Microsoft.AspNetCore.OpenApi from Net8JwtBearerSample.csproj - Bump JwtBearer package to 10.0.1 for net10.0 - Add bearerFormat ("JWT") to OpenAPI security scheme - Rename errorSchema to problemDetailsSchema for clarity --- .editorconfig | 1 - .../Net8JwtBearerSample/Net8JwtBearerSample.csproj | 1 - .../SimpleAuthentication.Abstractions.csproj | 2 +- .../OpenApi/AuthenticationDocumentTransformer.cs | 7 ++++--- .../OpenApi/DefaultResponseDocumentTransformer.cs | 5 ++--- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.editorconfig b/.editorconfig index 8f8512a..1a27cc7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -82,7 +82,6 @@ csharp_style_prefer_local_over_anonymous_function = true:silent csharp_style_prefer_extended_property_pattern = true:suggestion csharp_style_implicit_object_creation_when_type_is_apparent = true:silent csharp_style_prefer_tuple_swap = true:silent -csharp_style_prefer_simple_property_accessors = true:suggestion # Field preferences dotnet_style_readonly_field = true:suggestion diff --git a/samples/MinimalApis/Net8JwtBearerSample/Net8JwtBearerSample.csproj b/samples/MinimalApis/Net8JwtBearerSample/Net8JwtBearerSample.csproj index 78b0e0f..6d59ca3 100644 --- a/samples/MinimalApis/Net8JwtBearerSample/Net8JwtBearerSample.csproj +++ b/samples/MinimalApis/Net8JwtBearerSample/Net8JwtBearerSample.csproj @@ -7,7 +7,6 @@ - diff --git a/src/SimpleAuthentication.Abstractions/SimpleAuthentication.Abstractions.csproj b/src/SimpleAuthentication.Abstractions/SimpleAuthentication.Abstractions.csproj index d05f562..ba7a93f 100644 --- a/src/SimpleAuthentication.Abstractions/SimpleAuthentication.Abstractions.csproj +++ b/src/SimpleAuthentication.Abstractions/SimpleAuthentication.Abstractions.csproj @@ -36,7 +36,7 @@ - + diff --git a/src/SimpleAuthentication/OpenApi/AuthenticationDocumentTransformer.cs b/src/SimpleAuthentication/OpenApi/AuthenticationDocumentTransformer.cs index 96b8e87..c78d266 100644 --- a/src/SimpleAuthentication/OpenApi/AuthenticationDocumentTransformer.cs +++ b/src/SimpleAuthentication/OpenApi/AuthenticationDocumentTransformer.cs @@ -157,7 +157,7 @@ static void CheckAddJwtBearer(OpenApiDocument document, IConfigurationSection se return; } - AddSecurityScheme(document, settings.SchemeName, SecuritySchemeType.Http, JwtBearerDefaults.AuthenticationScheme, ParameterLocation.Header, HeaderNames.Authorization, "Insert the Bearer Token"); + AddSecurityScheme(document, settings.SchemeName, SecuritySchemeType.Http, JwtBearerDefaults.AuthenticationScheme, ParameterLocation.Header, HeaderNames.Authorization, "Insert the Bearer Token", "JWT"); AddSecurityRequirement(document, settings.SchemeName); } @@ -199,7 +199,7 @@ static void CheckAddBasicAuthentication(OpenApiDocument document, IConfiguration } } - private static void AddSecurityScheme(OpenApiDocument document, string name, SecuritySchemeType securitySchemeType, string? scheme, ParameterLocation location, string parameterName, string description) + private static void AddSecurityScheme(OpenApiDocument document, string name, SecuritySchemeType securitySchemeType, string? scheme, ParameterLocation location, string parameterName, string description, string? bearerFormat = null) { document.Components ??= new(); document.Components.SecuritySchemes ??= new Dictionary(); @@ -210,7 +210,8 @@ private static void AddSecurityScheme(OpenApiDocument document, string name, Sec Name = parameterName, Description = description, Type = securitySchemeType, - Scheme = scheme + Scheme = scheme, + BearerFormat = bearerFormat }); } diff --git a/src/SimpleAuthentication/OpenApi/DefaultResponseDocumentTransformer.cs b/src/SimpleAuthentication/OpenApi/DefaultResponseDocumentTransformer.cs index 78cb6d4..a262b45 100644 --- a/src/SimpleAuthentication/OpenApi/DefaultResponseDocumentTransformer.cs +++ b/src/SimpleAuthentication/OpenApi/DefaultResponseDocumentTransformer.cs @@ -62,7 +62,6 @@ public Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransformerC #elif NET10_0_OR_GREATER -using System.Net.Mime; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.OpenApi; using Microsoft.OpenApi; @@ -74,8 +73,8 @@ internal class DefaultResponseDocumentTransformer : IOpenApiDocumentTransformer public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransformerContext context, CancellationToken cancellationToken) { // Generate schema for error responses. - var errorSchema = await context.GetOrCreateSchemaAsync(typeof(ProblemDetails), cancellationToken: cancellationToken); - document.AddComponent(nameof(ProblemDetails), errorSchema); + var problemDetailsSchema = await context.GetOrCreateSchemaAsync(typeof(ProblemDetails), cancellationToken: cancellationToken); + document.AddComponent(nameof(ProblemDetails), problemDetailsSchema); } } From 883396f4ea5436ad19ecf9b4ede511b3bf38d59b Mon Sep 17 00:00:00 2001 From: Marco Minerva Date: Wed, 10 Dec 2025 11:23:47 +0100 Subject: [PATCH 2/2] Enable simple property accessor suggestion in .editorconfig Added csharp_style_prefer_simple_property_accessors = true:suggestion to .editorconfig to encourage concise property definitions in C# code. This helps promote cleaner and more maintainable code by preferring simple property accessors where applicable. --- .editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/.editorconfig b/.editorconfig index 1a27cc7..8f8512a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -82,6 +82,7 @@ csharp_style_prefer_local_over_anonymous_function = true:silent csharp_style_prefer_extended_property_pattern = true:suggestion csharp_style_implicit_object_creation_when_type_is_apparent = true:silent csharp_style_prefer_tuple_swap = true:silent +csharp_style_prefer_simple_property_accessors = true:suggestion # Field preferences dotnet_style_readonly_field = true:suggestion