From f8d28df3d808f5b8c6d22904a719406eecdcca84 Mon Sep 17 00:00:00 2001 From: martincostello Date: Sun, 12 Jan 2025 16:14:27 +0000 Subject: [PATCH] Add CreateFromJson options overload - Add overload to `OpenApiAnyFactory.CreateFromJson()` that supports passing in a `JsonSerializerOptions` as a workaround for #3217. - Use concrete types as suggested by analyzers. - Move unshipped APIs to shipped. - Bump version to 7.3.0. --- Directory.Build.props | 2 +- .../PublicAPI/PublicAPI.Shipped.txt | 2 ++ .../PublicAPI/PublicAPI.Unshipped.txt | 2 -- .../PublicAPI/PublicAPI.Shipped.txt | 10 +++++++++ .../PublicAPI/PublicAPI.Unshipped.txt | 11 +--------- .../SwaggerGenerator/OpenApiAnyFactory.cs | 22 +++++++++++-------- .../PublicAPI/PublicAPI.Shipped.txt | 2 ++ .../PublicAPI/PublicAPI.Unshipped.txt | 2 -- 8 files changed, 29 insertions(+), 24 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 8a9a25617b..e5ebe4d2f8 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -42,7 +42,7 @@ snupkg true true - 7.2.1 + 7.3.0 false diff --git a/src/Swashbuckle.AspNetCore.ReDoc/PublicAPI/PublicAPI.Shipped.txt b/src/Swashbuckle.AspNetCore.ReDoc/PublicAPI/PublicAPI.Shipped.txt index fcd2184d8a..de8aab6791 100644 --- a/src/Swashbuckle.AspNetCore.ReDoc/PublicAPI/PublicAPI.Shipped.txt +++ b/src/Swashbuckle.AspNetCore.ReDoc/PublicAPI/PublicAPI.Shipped.txt @@ -56,6 +56,8 @@ Swashbuckle.AspNetCore.ReDoc.ReDocOptions.HeadContent.get -> string Swashbuckle.AspNetCore.ReDoc.ReDocOptions.HeadContent.set -> void Swashbuckle.AspNetCore.ReDoc.ReDocOptions.IndexStream.get -> System.Func Swashbuckle.AspNetCore.ReDoc.ReDocOptions.IndexStream.set -> void +Swashbuckle.AspNetCore.ReDoc.ReDocOptions.JsonSerializerOptions.get -> System.Text.Json.JsonSerializerOptions +Swashbuckle.AspNetCore.ReDoc.ReDocOptions.JsonSerializerOptions.set -> void Swashbuckle.AspNetCore.ReDoc.ReDocOptions.ReDocOptions() -> void Swashbuckle.AspNetCore.ReDoc.ReDocOptions.RoutePrefix.get -> string Swashbuckle.AspNetCore.ReDoc.ReDocOptions.RoutePrefix.set -> void diff --git a/src/Swashbuckle.AspNetCore.ReDoc/PublicAPI/PublicAPI.Unshipped.txt b/src/Swashbuckle.AspNetCore.ReDoc/PublicAPI/PublicAPI.Unshipped.txt index 153757a7c1..e69de29bb2 100644 --- a/src/Swashbuckle.AspNetCore.ReDoc/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/Swashbuckle.AspNetCore.ReDoc/PublicAPI/PublicAPI.Unshipped.txt @@ -1,2 +0,0 @@ -Swashbuckle.AspNetCore.ReDoc.ReDocOptions.JsonSerializerOptions.get -> System.Text.Json.JsonSerializerOptions -Swashbuckle.AspNetCore.ReDoc.ReDocOptions.JsonSerializerOptions.set -> void diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/PublicAPI.Shipped.txt b/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/PublicAPI.Shipped.txt index 7c98e81b26..695cbeb8bd 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/PublicAPI.Shipped.txt +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/PublicAPI.Shipped.txt @@ -1,8 +1,12 @@ Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions Microsoft.Extensions.DependencyInjection.SwaggerGenServiceCollectionExtensions +static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddDocumentAsyncFilterInstance(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddDocumentFilterInstance(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void +static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddOperationAsyncFilterInstance(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddOperationFilterInstance(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void +static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddParameterAsyncFilterInstance(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddParameterFilterInstance(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void +static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddRequestBodyAsyncFilterInstance(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddRequestBodyFilterInstance(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddSchemaFilterInstance(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddSecurityDefinition(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, string name, Microsoft.OpenApi.Models.OpenApiSecurityScheme securityScheme) -> void @@ -11,6 +15,7 @@ static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddS static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.CustomOperationIds(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, System.Func operationIdSelector) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.CustomSchemaIds(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, System.Func schemaIdSelector) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.DescribeAllParametersInCamelCase(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions) -> void +static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.DocumentAsyncFilter(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.DocInclusionPredicate(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, System.Func predicate) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.DocumentFilter(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.GeneratePolymorphicSchemas(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, System.Func> subTypesResolver = null, System.Func discriminatorSelector = null) -> void @@ -23,9 +28,12 @@ static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.Infe static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, System.Type type, System.Func schemaFactory) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, System.Func schemaFactory) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.NonNullableReferenceTypesAsRequired(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions) -> void +static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.OperationAsyncFilter(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.OperationFilter(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.OrderActionsBy(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, System.Func sortKeySelector) -> void +static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.ParameterAsyncFilter(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.ParameterFilter(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void +static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.RequestBodyAsyncFilter(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.RequestBodyFilter(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.ResolveConflictingActions(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, System.Func, Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription> resolver) -> void static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.SchemaFilter(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void @@ -266,6 +274,8 @@ Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.ParameterAsyncFilters. Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.ParameterAsyncFilters.set -> void Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.ParameterFilters.get -> System.Collections.Generic.IList Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.ParameterFilters.set -> void +Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.PathGroupSelector.get -> System.Func +Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.PathGroupSelector.set -> void Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.RequestBodyAsyncFilters.get -> System.Collections.Generic.IList Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.RequestBodyAsyncFilters.set -> void Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.RequestBodyFilters.get -> System.Collections.Generic.List diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/PublicAPI.Unshipped.txt b/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/PublicAPI.Unshipped.txt index fb4f007a9d..57462c2db8 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/PublicAPI/PublicAPI.Unshipped.txt @@ -1,10 +1 @@ -static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddDocumentAsyncFilterInstance(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void -static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddOperationAsyncFilterInstance(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void -static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddParameterAsyncFilterInstance(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void -static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddRequestBodyAsyncFilterInstance(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void -static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.DocumentAsyncFilter(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void -static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.OperationAsyncFilter(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void -static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.ParameterAsyncFilter(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void -static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.RequestBodyAsyncFilter(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void -Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.PathGroupSelector.get -> System.Func -Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.PathGroupSelector.set -> void +static Swashbuckle.AspNetCore.SwaggerGen.OpenApiAnyFactory.CreateFromJson(string json, System.Text.Json.JsonSerializerOptions options) -> Microsoft.OpenApi.Any.IOpenApiAny diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/OpenApiAnyFactory.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/OpenApiAnyFactory.cs index b28aa21958..5794645ff9 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/OpenApiAnyFactory.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/OpenApiAnyFactory.cs @@ -1,4 +1,5 @@ -using System.Text.Json; +using System; +using System.Text.Json; using Microsoft.OpenApi.Any; namespace Swashbuckle.AspNetCore.SwaggerGen @@ -6,19 +7,22 @@ namespace Swashbuckle.AspNetCore.SwaggerGen public static class OpenApiAnyFactory { public static IOpenApiAny CreateFromJson(string json) + => CreateFromJson(json, null); + + public static IOpenApiAny CreateFromJson(string json, JsonSerializerOptions options) { try { - var jsonElement = JsonSerializer.Deserialize(json); - - return CreateFromJsonElement(jsonElement); + var element = JsonSerializer.Deserialize(json, options); + return CreateFromJsonElement(element); + } + catch (Exception) + { + return null; } - catch { } - - return null; } - private static IOpenApiAny CreateOpenApiArray(JsonElement jsonElement) + private static OpenApiArray CreateOpenApiArray(JsonElement jsonElement) { var openApiArray = new OpenApiArray(); @@ -30,7 +34,7 @@ private static IOpenApiAny CreateOpenApiArray(JsonElement jsonElement) return openApiArray; } - private static IOpenApiAny CreateOpenApiObject(JsonElement jsonElement) + private static OpenApiObject CreateOpenApiObject(JsonElement jsonElement) { var openApiObject = new OpenApiObject(); diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Shipped.txt b/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Shipped.txt index 10a51b8ceb..572eb0f5df 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Shipped.txt +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Shipped.txt @@ -60,6 +60,8 @@ Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.OAuth2RedirectUrl.get -> string Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.OAuth2RedirectUrl.set -> void Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.PersistAuthorization.get -> bool Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.PersistAuthorization.set -> void +Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.Plugins.get -> System.Collections.Generic.IList +Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.Plugins.set -> void Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.ShowCommonExtensions.get -> bool Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.ShowCommonExtensions.set -> void Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.ShowExtensions.get -> bool diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Unshipped.txt b/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Unshipped.txt index 7d361b8837..e69de29bb2 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/PublicAPI/PublicAPI.Unshipped.txt @@ -1,2 +0,0 @@ -Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.Plugins.get -> System.Collections.Generic.IList -Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.Plugins.set -> void