Skip to content

Commit 7dd16f6

Browse files
committed
Fixed the EndpointMetadata population
1 parent ed534a8 commit 7dd16f6

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/Mvc/Mvc.ApiExplorer/src/ApiResponseTypeProvider.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,8 @@ internal static void CalculateResponseFormatForType(ApiResponseType apiResponse,
364364

365365
// If the method is declared to return IActionResult, IResult or a derived class, that information
366366
// isn't valuable to the formatter, unless it implements IEndpointMetadataProvider interface.
367-
bool isIResultOrIActionResult = typeof(IActionResult).IsAssignableFrom(unwrappedType) ||
368-
typeof(IResult).IsAssignableFrom(unwrappedType);
369-
if (isIResultOrIActionResult && !typeof(IEndpointMetadataProvider).IsAssignableFrom(unwrappedType))
367+
if (typeof(IActionResult).IsAssignableFrom(unwrappedType) ||
368+
typeof(IResult).IsAssignableFrom(unwrappedType))
370369
{
371370
return null;
372371
}

src/Mvc/Mvc.Core/src/ApplicationModels/DefaultApplicationModelProvider.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,13 @@ internal PropertyModel CreatePropertyModel(PropertyInfo propertyInfo)
353353
applicableAttributes.AddRange(routeAttributes);
354354
AddRange(actionModel.Selectors, CreateSelectors(applicableAttributes));
355355

356-
// There may be additional metadata for the action that is associated with the return type.
357-
AddEndpointMetadata(actionModel, methodInfo);
356+
AddReturnTypeMetadata(actionModel.Selectors, methodInfo);
357+
358358

359359
return actionModel;
360360
}
361361

362-
private static void AddEndpointMetadata(ActionModel actionModel, MethodInfo methodInfo)
362+
private static void AddReturnTypeMetadata(IList<SelectorModel> selectors, MethodInfo methodInfo)
363363
{
364364
// Get metadata from return type
365365
var returnType = methodInfo.ReturnType;
@@ -376,6 +376,16 @@ private static void AddEndpointMetadata(ActionModel actionModel, MethodInfo meth
376376
invokeArgs[0] = methodInfo;
377377
invokeArgs[1] = builder;
378378
PopulateMetadataForEndpointMethod.MakeGenericMethod(returnType).Invoke(null, invokeArgs);
379+
380+
// The metadata is added to the builder's metadata collection.
381+
// We need to populate the selectors with that metadata.
382+
foreach (var metadata in builder.Metadata)
383+
{
384+
foreach (var selector in selectors)
385+
{
386+
selector.EndpointMetadata.Add(metadata);
387+
}
388+
}
379389
}
380390
}
381391

0 commit comments

Comments
 (0)