4
4
using Microsoft . OpenApi . Models ;
5
5
using Swashbuckle . AspNetCore . SwaggerGen ;
6
6
using System . Linq ;
7
+ using System . Text . Json ;
7
8
8
9
/// <summary>
9
10
/// Represents the Swagger/Swashbuckle operation filter used to document the implicit API version parameter.
@@ -23,15 +24,13 @@ public void Apply( OpenApiOperation operation, OperationFilterContext context )
23
24
24
25
operation . Deprecated |= apiDescription . IsDeprecated ( ) ;
25
26
26
- // https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1752#issue-663991077
27
+ // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1752#issue-663991077
27
28
foreach ( var responseType in context . ApiDescription . SupportedResponseTypes )
28
29
{
29
- // based on internals of SwaggerGenerator
30
- // https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/b7cf75e7905050305b115dd96640ddd6e74c7ac9/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs#L383-L387
30
+ // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/b7cf75e7905050305b115dd96640ddd6e74c7ac9/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs#L383-L387
31
31
var responseKey = responseType . IsDefaultResponse ? "default" : responseType . StatusCode . ToString ( ) ;
32
32
var response = operation . Responses [ responseKey ] ;
33
33
34
- // remove media types not supported by the API
35
34
foreach ( var contentType in response . Content . Keys )
36
35
{
37
36
if ( ! responseType . ApiResponseFormats . Any ( x => x . MediaType == contentType ) )
@@ -59,8 +58,9 @@ public void Apply( OpenApiOperation operation, OperationFilterContext context )
59
58
60
59
if ( parameter . Schema . Default == null && description . DefaultValue != null )
61
60
{
62
- // https://github.com/Microsoft/aspnet-api-versioning/issues/429#issuecomment-605402330
63
- parameter . Schema . Default = OpenApiAnyFactory . CreateFor ( parameter . Schema , description . DefaultValue ) ;
61
+ // REF: https://github.com/Microsoft/aspnet-api-versioning/issues/429#issuecomment-605402330
62
+ var json = JsonSerializer . Serialize ( description . DefaultValue , description . ModelMetadata . ModelType ) ;
63
+ parameter . Schema . Default = OpenApiAnyFactory . CreateFromJson ( json ) ;
64
64
}
65
65
66
66
parameter . Required |= description . IsRequired ;
0 commit comments