@@ -52,7 +52,7 @@ public void OnProvidersExecuted(ApiDescriptionProviderContext context)
5252 {
5353 }
5454
55- private static ApiDescription CreateApiDescription ( RoutePattern pattern , string httpMethod , MethodInfo actionMethodInfo )
55+ private static ApiDescription CreateApiDescription ( RoutePattern pattern , string httpMethod , MethodInfo methodInfo )
5656 {
5757 var apiDescription = new ApiDescription
5858 {
@@ -65,17 +65,34 @@ private static ApiDescription CreateApiDescription(RoutePattern pattern, string
6565 // Swagger uses this to group endpoints together.
6666 // For now, put all endpoints configured with Map(Delegate) together.
6767 // TODO: Use some other metadata for this.
68- [ "controller" ] = "Map"
68+ [ "controller" ] = "Map" ,
6969 } ,
7070 } ,
7171 } ;
7272
73- foreach ( var parameter in actionMethodInfo . GetParameters ( ) )
73+ var hasJsonBody = false ;
74+
75+ foreach ( var parameter in methodInfo . GetParameters ( ) )
7476 {
77+ var parameterDescription = CreateApiParameterDescription ( parameter , pattern ) ;
78+
79+ if ( parameterDescription . Source == BindingSource . Body )
80+ {
81+ hasJsonBody = true ;
82+ }
83+
7584 apiDescription . ParameterDescriptions . Add ( CreateApiParameterDescription ( parameter , pattern ) ) ;
7685 }
7786
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 ;
7996
8097 if ( AwaitableInfo . IsTypeAwaitable ( responseType , out var awaitableInfo ) )
8198 {
@@ -134,7 +151,7 @@ private static (BindingSource, string) GetBindingSourceAndName(ParameterInfo par
134151 parameter . ParameterType == typeof ( CancellationToken ) ||
135152 parameter . ParameterType . IsInterface )
136153 {
137- return ( BindingSource . Body , parameter . Name ?? string . Empty ) ;
154+ return ( BindingSource . Services , parameter . Name ?? string . Empty ) ;
138155 }
139156 else if ( parameter . ParameterType == typeof ( string ) || RequestDelegateFactoryUtilities . HasTryParseMethod ( parameter ) )
140157 {
0 commit comments