@@ -87,14 +87,7 @@ private static ApiDescription CreateApiDescription(RouteEndpoint routeEndpoint,
87
87
apiDescription . ParameterDescriptions . Add ( parameterDescription ) ;
88
88
}
89
89
90
- if ( hasJsonBody )
91
- {
92
- apiDescription . SupportedRequestFormats . Add ( new ApiRequestFormat
93
- {
94
- MediaType = "application/json" ,
95
- } ) ;
96
- }
97
-
90
+ AddSupportedRequestFormats ( apiDescription . SupportedRequestFormats , hasJsonBody , routeEndpoint . Metadata ) ;
98
91
AddSupportedResponseTypes ( apiDescription . SupportedResponseTypes , methodInfo . ReturnType , routeEndpoint . Metadata ) ;
99
92
100
93
return apiDescription ;
@@ -160,7 +153,35 @@ private static (BindingSource, string) GetBindingSourceAndName(ParameterInfo par
160
153
}
161
154
}
162
155
163
- private static void AddSupportedResponseTypes ( IList < ApiResponseType > supportedResponseTypes , Type returnType , EndpointMetadataCollection endpointMetadata )
156
+ private static void AddSupportedRequestFormats (
157
+ IList < ApiRequestFormat > supportedRequestFormats ,
158
+ bool hasJsonBody ,
159
+ EndpointMetadataCollection endpointMetadata )
160
+ {
161
+ // If RequestDelegateFactory thinks the API supports a JSON body, it does.
162
+ if ( hasJsonBody )
163
+ {
164
+ supportedRequestFormats . Add ( new ApiRequestFormat
165
+ {
166
+ MediaType = "application/json" ,
167
+ } ) ;
168
+ }
169
+
170
+ var requestMetadata = endpointMetadata . GetOrderedMetadata < IApiRequestMetadataProvider > ( ) ;
171
+
172
+ foreach ( var contentType in DefaultApiDescriptionProvider . GetDeclaredContentTypes ( requestMetadata ) )
173
+ {
174
+ supportedRequestFormats . Add ( new ApiRequestFormat
175
+ {
176
+ MediaType = contentType ,
177
+ } ) ;
178
+ }
179
+ }
180
+
181
+ private static void AddSupportedResponseTypes (
182
+ IList < ApiResponseType > supportedResponseTypes ,
183
+ Type returnType ,
184
+ EndpointMetadataCollection endpointMetadata )
164
185
{
165
186
var responseType = returnType ;
166
187
@@ -180,7 +201,8 @@ private static void AddSupportedResponseTypes(IList<ApiResponseType> supportedRe
180
201
var defaultErrorType = errorMetadata ? . Type ?? typeof ( void ) ;
181
202
var contentTypes = new MediaTypeCollection ( ) ;
182
203
183
- var responseMetadataTypes = ApiResponseTypeProvider . ReadResponseMetadata ( responseMetadata , responseType , defaultErrorType , contentTypes ) ;
204
+ var responseMetadataTypes = ApiResponseTypeProvider . ReadResponseMetadata (
205
+ responseMetadata , responseType , defaultErrorType , contentTypes ) ;
184
206
185
207
if ( responseMetadataTypes . Count > 0 )
186
208
{
@@ -236,7 +258,7 @@ private static ApiResponseType CreateDefaultApiResponseType(Type responseType)
236
258
237
259
private static ApiResponseFormat ? CreateDefaultApiResponseFormat ( Type responseType )
238
260
{
239
- if ( responseType == typeof ( void ) || typeof ( IResult ) . IsAssignableFrom ( responseType ) )
261
+ if ( responseType == typeof ( void ) )
240
262
{
241
263
return null ;
242
264
}
0 commit comments