1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Reflection ;
4
+ using System . Text . Json ;
4
5
using JsonApiDotNetCore . Configuration ;
5
6
using JsonApiDotNetCore . Middleware ;
6
7
using JsonApiDotNetCore . OpenApi . SwaggerComponents ;
7
8
using Microsoft . AspNetCore . Mvc . ApiExplorer ;
8
9
using Microsoft . AspNetCore . Mvc . Infrastructure ;
9
10
using Microsoft . Extensions . DependencyInjection ;
10
- using Newtonsoft . Json . Serialization ;
11
11
using Swashbuckle . AspNetCore . Swagger ;
12
12
using Swashbuckle . AspNetCore . SwaggerGen ;
13
13
@@ -57,16 +57,16 @@ private static void AddCustomApiExplorer(IServiceCollection services, IMvcCoreBu
57
57
private static void AddSwaggerGenerator ( IServiceScope scope , IServiceCollection services , Action < SwaggerGenOptions > setupSwaggerGenAction )
58
58
{
59
59
var controllerResourceMapping = scope . ServiceProvider . GetRequiredService < IControllerResourceMapping > ( ) ;
60
- var resourceContextProvider = scope . ServiceProvider . GetRequiredService < IResourceContextProvider > ( ) ;
60
+ var resourceGraph = scope . ServiceProvider . GetRequiredService < IResourceGraph > ( ) ;
61
61
var jsonApiOptions = scope . ServiceProvider . GetRequiredService < IJsonApiOptions > ( ) ;
62
- NamingStrategy namingStrategy = ( ( DefaultContractResolver ) jsonApiOptions . SerializerSettings . ContractResolver ) ! . NamingStrategy ;
62
+ var namingPolicy = jsonApiOptions . SerializerOptions . PropertyNamingPolicy ;
63
63
64
64
AddSchemaGenerator ( services ) ;
65
65
66
66
services . AddSwaggerGen ( swaggerGenOptions =>
67
67
{
68
- SetOperationInfo ( swaggerGenOptions , controllerResourceMapping , resourceContextProvider , namingStrategy ) ;
69
- SetSchemaIdSelector ( swaggerGenOptions , resourceContextProvider , namingStrategy ) ;
68
+ SetOperationInfo ( swaggerGenOptions , controllerResourceMapping , resourceGraph , namingPolicy ) ;
69
+ SetSchemaIdSelector ( swaggerGenOptions , resourceGraph , namingPolicy ) ;
70
70
swaggerGenOptions . DocumentFilter < EndpointOrderingFilter > ( ) ;
71
71
72
72
setupSwaggerGenAction ? . Invoke ( swaggerGenOptions ) ;
@@ -80,32 +80,32 @@ private static void AddSchemaGenerator(IServiceCollection services)
80
80
}
81
81
82
82
private static void SetOperationInfo ( SwaggerGenOptions swaggerGenOptions , IControllerResourceMapping controllerResourceMapping ,
83
- IResourceContextProvider resourceContextProvider , NamingStrategy namingStrategy )
83
+ IResourceGraph resourceGraph , JsonNamingPolicy namingPolicy )
84
84
{
85
- swaggerGenOptions . TagActionsBy ( description => GetOperationTags ( description , controllerResourceMapping , resourceContextProvider ) ) ;
85
+ swaggerGenOptions . TagActionsBy ( description => GetOperationTags ( description , controllerResourceMapping , resourceGraph ) ) ;
86
86
87
- JsonApiOperationIdSelector jsonApiOperationIdSelector = new ( controllerResourceMapping , namingStrategy ) ;
87
+ JsonApiOperationIdSelector jsonApiOperationIdSelector = new ( controllerResourceMapping , namingPolicy ) ;
88
88
swaggerGenOptions . CustomOperationIds ( jsonApiOperationIdSelector . GetOperationId ) ;
89
89
}
90
90
91
91
private static IList < string > GetOperationTags ( ApiDescription description , IControllerResourceMapping controllerResourceMapping ,
92
- IResourceContextProvider resourceContextProvider )
92
+ IResourceGraph resourceGraph )
93
93
{
94
94
MethodInfo actionMethod = description . ActionDescriptor . GetActionMethod ( ) ;
95
95
Type resourceType = controllerResourceMapping . GetResourceTypeForController ( actionMethod . ReflectedType ) ;
96
- ResourceContext resourceContext = resourceContextProvider . GetResourceContext ( resourceType ) ;
96
+ ResourceContext resourceContext = resourceGraph . GetResourceContext ( resourceType ) ;
97
97
98
98
return new [ ]
99
99
{
100
100
resourceContext . PublicName
101
101
} ;
102
102
}
103
103
104
- private static void SetSchemaIdSelector ( SwaggerGenOptions swaggerGenOptions , IResourceContextProvider resourceContextProvider ,
105
- NamingStrategy namingStrategy )
104
+ private static void SetSchemaIdSelector ( SwaggerGenOptions swaggerGenOptions , IResourceGraph resourceGraph ,
105
+ JsonNamingPolicy namingPolicy )
106
106
{
107
- ResourceNameFormatter resourceNameFormatter = new ( namingStrategy ) ;
108
- JsonApiSchemaIdSelector jsonApiObjectSchemaSelector = new ( resourceNameFormatter , resourceContextProvider ) ;
107
+ ResourceNameFormatter resourceNameFormatter = new ( namingPolicy ) ;
108
+ JsonApiSchemaIdSelector jsonApiObjectSchemaSelector = new ( resourceNameFormatter , resourceGraph ) ;
109
109
110
110
swaggerGenOptions . CustomSchemaIds ( type => jsonApiObjectSchemaSelector . GetSchemaId ( type ) ) ;
111
111
}
@@ -127,10 +127,10 @@ private static void AddSwashbuckleCliCompatibility(IServiceScope scope, IMvcCore
127
127
128
128
private static void AddOpenApiEndpointConvention ( IServiceScope scope , IMvcCoreBuilder mvcBuilder )
129
129
{
130
- var resourceContextProvider = scope . ServiceProvider . GetRequiredService < IResourceContextProvider > ( ) ;
130
+ var resourceGraph = scope . ServiceProvider . GetRequiredService < IResourceGraph > ( ) ;
131
131
var controllerResourceMapping = scope . ServiceProvider . GetRequiredService < IControllerResourceMapping > ( ) ;
132
132
133
- mvcBuilder . AddMvcOptions ( options => options . Conventions . Add ( new OpenApiEndpointConvention ( resourceContextProvider , controllerResourceMapping ) ) ) ;
133
+ mvcBuilder . AddMvcOptions ( options => options . Conventions . Add ( new OpenApiEndpointConvention ( resourceGraph , controllerResourceMapping ) ) ) ;
134
134
}
135
135
}
136
136
}
0 commit comments