@@ -52,7 +52,7 @@ public void OnProvidersExecuted(ApiDescriptionProviderContext context)
52
52
{
53
53
}
54
54
55
- private static ApiDescription CreateApiDescription ( RoutePattern pattern , string httpMethod , MethodInfo actionMethodInfo )
55
+ private static ApiDescription CreateApiDescription ( RoutePattern pattern , string httpMethod , MethodInfo methodInfo )
56
56
{
57
57
var apiDescription = new ApiDescription
58
58
{
@@ -65,17 +65,34 @@ private static ApiDescription CreateApiDescription(RoutePattern pattern, string
65
65
// Swagger uses this to group endpoints together.
66
66
// For now, put all endpoints configured with Map(Delegate) together.
67
67
// TODO: Use some other metadata for this.
68
- [ "controller" ] = "Map"
68
+ [ "controller" ] = "Map" ,
69
69
} ,
70
70
} ,
71
71
} ;
72
72
73
- foreach ( var parameter in actionMethodInfo . GetParameters ( ) )
73
+ var hasJsonBody = false ;
74
+
75
+ foreach ( var parameter in methodInfo . GetParameters ( ) )
74
76
{
77
+ var parameterDescription = CreateApiParameterDescription ( parameter , pattern ) ;
78
+
79
+ if ( parameterDescription . Source == BindingSource . Body )
80
+ {
81
+ hasJsonBody = true ;
82
+ }
83
+
75
84
apiDescription . ParameterDescriptions . Add ( CreateApiParameterDescription ( parameter , pattern ) ) ;
76
85
}
77
86
78
- var responseType = actionMethodInfo . ReturnType ;
87
+ if ( hasJsonBody )
88
+ {
89
+ apiDescription . SupportedRequestFormats . Add ( new ApiRequestFormat
90
+ {
91
+ MediaType = "application/json" ,
92
+ } ) ;
93
+ }
94
+
95
+ var responseType = methodInfo . ReturnType ;
79
96
80
97
if ( AwaitableInfo . IsTypeAwaitable ( responseType , out var awaitableInfo ) )
81
98
{
@@ -134,7 +151,7 @@ private static (BindingSource, string) GetBindingSourceAndName(ParameterInfo par
134
151
parameter . ParameterType == typeof ( CancellationToken ) ||
135
152
parameter . ParameterType . IsInterface )
136
153
{
137
- return ( BindingSource . Body , parameter . Name ?? string . Empty ) ;
154
+ return ( BindingSource . Services , parameter . Name ?? string . Empty ) ;
138
155
}
139
156
else if ( parameter . ParameterType == typeof ( string ) || RequestDelegateFactoryUtilities . HasTryParseMethod ( parameter ) )
140
157
{
0 commit comments