@@ -87,14 +87,7 @@ private static ApiDescription CreateApiDescription(RouteEndpoint routeEndpoint,
8787 apiDescription . ParameterDescriptions . Add ( parameterDescription ) ;
8888 }
8989
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 ) ;
9891 AddSupportedResponseTypes ( apiDescription . SupportedResponseTypes , methodInfo . ReturnType , routeEndpoint . Metadata ) ;
9992
10093 return apiDescription ;
@@ -160,7 +153,35 @@ private static (BindingSource, string) GetBindingSourceAndName(ParameterInfo par
160153 }
161154 }
162155
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 )
164185 {
165186 var responseType = returnType ;
166187
@@ -180,7 +201,8 @@ private static void AddSupportedResponseTypes(IList<ApiResponseType> supportedRe
180201 var defaultErrorType = errorMetadata ? . Type ?? typeof ( void ) ;
181202 var contentTypes = new MediaTypeCollection ( ) ;
182203
183- var responseMetadataTypes = ApiResponseTypeProvider . ReadResponseMetadata ( responseMetadata , responseType , defaultErrorType , contentTypes ) ;
204+ var responseMetadataTypes = ApiResponseTypeProvider . ReadResponseMetadata (
205+ responseMetadata , responseType , defaultErrorType , contentTypes ) ;
184206
185207 if ( responseMetadataTypes . Count > 0 )
186208 {
@@ -236,7 +258,7 @@ private static ApiResponseType CreateDefaultApiResponseType(Type responseType)
236258
237259 private static ApiResponseFormat ? CreateDefaultApiResponseFormat ( Type responseType )
238260 {
239- if ( responseType == typeof ( void ) || typeof ( IResult ) . IsAssignableFrom ( responseType ) )
261+ if ( responseType == typeof ( void ) )
240262 {
241263 return null ;
242264 }
0 commit comments