Skip to content

Commit

Permalink
Add CreateFromJson options overload
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
martincostello committed Jan 20, 2025
1 parent 5f20430 commit f8d28df
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<UseArtifactsOutput>true</UseArtifactsOutput>
<VersionPrefix>7.2.1</VersionPrefix>
<VersionPrefix>7.3.0</VersionPrefix>
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>
</PropertyGroup>
<PropertyGroup Condition=" '$(GITHUB_ACTIONS)' != '' ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<System.IO.Stream>
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
Swashbuckle.AspNetCore.ReDoc.ReDocOptions.JsonSerializerOptions.get -> System.Text.Json.JsonSerializerOptions
Swashbuckle.AspNetCore.ReDoc.ReDocOptions.JsonSerializerOptions.set -> void
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions
Microsoft.Extensions.DependencyInjection.SwaggerGenServiceCollectionExtensions
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddDocumentAsyncFilterInstance<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddDocumentFilterInstance<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddOperationAsyncFilterInstance<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddOperationFilterInstance<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddParameterAsyncFilterInstance<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddParameterFilterInstance<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddRequestBodyAsyncFilterInstance<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddRequestBodyFilterInstance<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddSchemaFilterInstance<TFilter>(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
Expand All @@ -11,6 +15,7 @@ static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddS
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.CustomOperationIds(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, System.Func<Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription, string> operationIdSelector) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.CustomSchemaIds(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, System.Func<System.Type, string> schemaIdSelector) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.DescribeAllParametersInCamelCase(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.DocumentAsyncFilter<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.DocInclusionPredicate(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, System.Func<string, Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription, bool> predicate) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.DocumentFilter<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.GeneratePolymorphicSchemas(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, System.Func<System.Type, System.Collections.Generic.IEnumerable<System.Type>> subTypesResolver = null, System.Func<System.Type, string> discriminatorSelector = null) -> void
Expand All @@ -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<Microsoft.OpenApi.Models.OpenApiSchema> schemaFactory) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.MapType<T>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, System.Func<Microsoft.OpenApi.Models.OpenApiSchema> schemaFactory) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.NonNullableReferenceTypesAsRequired(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.OperationAsyncFilter<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.OperationFilter<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.OrderActionsBy(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, System.Func<Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription, string> sortKeySelector) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.ParameterAsyncFilter<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.ParameterFilter<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.RequestBodyAsyncFilter<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.RequestBodyFilter<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.ResolveConflictingActions(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, System.Func<System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription>, Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription> resolver) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.SchemaFilter<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void
Expand Down Expand Up @@ -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.IParameterFilter>
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.ParameterFilters.set -> void
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.PathGroupSelector.get -> System.Func<Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription, string>
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.PathGroupSelector.set -> void
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.RequestBodyAsyncFilters.get -> System.Collections.Generic.IList<Swashbuckle.AspNetCore.SwaggerGen.IRequestBodyAsyncFilter>
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.RequestBodyAsyncFilters.set -> void
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.RequestBodyFilters.get -> System.Collections.Generic.List<Swashbuckle.AspNetCore.SwaggerGen.IRequestBodyFilter>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddDocumentAsyncFilterInstance<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddOperationAsyncFilterInstance<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddParameterAsyncFilterInstance<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.AddRequestBodyAsyncFilterInstance<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, TFilter filterInstance) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.DocumentAsyncFilter<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.OperationAsyncFilter<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.ParameterAsyncFilter<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void
static Microsoft.Extensions.DependencyInjection.SwaggerGenOptionsExtensions.RequestBodyAsyncFilter<TFilter>(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions swaggerGenOptions, params object[] arguments) -> void
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.PathGroupSelector.get -> System.Func<Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription, string>
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorOptions.PathGroupSelector.set -> void
static Swashbuckle.AspNetCore.SwaggerGen.OpenApiAnyFactory.CreateFromJson(string json, System.Text.Json.JsonSerializerOptions options) -> Microsoft.OpenApi.Any.IOpenApiAny
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
using System.Text.Json;
using System;
using System.Text.Json;
using Microsoft.OpenApi.Any;

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<JsonElement>(json);

return CreateFromJsonElement(jsonElement);
var element = JsonSerializer.Deserialize<JsonElement>(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();

Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.Plugins.get -> System.Collections.Generic.IList<string>
Swashbuckle.AspNetCore.SwaggerUI.ConfigObject.Plugins.set -> void

0 comments on commit f8d28df

Please sign in to comment.