Skip to content

Commit fad4923

Browse files
committed
Use local method as requested by PR comment
1 parent a083307 commit fad4923

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ private static void AddSupportedResponseTypes(
376376
}
377377

378378
// We set the Description to the LAST non-null value we find that matches the status code.
379-
apiResponseType.Description ??= responseMetadataTypes.LastOrDefault(x => x.StatusCode == apiResponseType.StatusCode && x.Type == apiResponseType.Type && x.Description is not null)?.Description;
379+
apiResponseType.Description ??= GetMatchingResponseTypeDescription(responseProviderMetadataTypes.Values, apiResponseType);
380380

381381
if (!supportedResponseTypes.Any(existingResponseType => existingResponseType.StatusCode == apiResponseType.StatusCode))
382382
{
@@ -398,6 +398,22 @@ private static void AddSupportedResponseTypes(
398398

399399
supportedResponseTypes.Add(defaultApiResponseType);
400400
}
401+
402+
static string? GetMatchingResponseTypeDescription(IEnumerable<ApiResponseType> responseMetadataTypes, ApiResponseType apiResponseType)
403+
{
404+
// We set the Description to the LAST non-null value we find that matches the status code.
405+
string? matchingDescription = null;
406+
foreach (var metadata in responseMetadataTypes)
407+
{
408+
if (metadata.StatusCode == apiResponseType.StatusCode &&
409+
metadata.Type == apiResponseType.Type &&
410+
metadata.Description is not null)
411+
{
412+
matchingDescription = metadata.Description;
413+
}
414+
}
415+
return matchingDescription;
416+
}
401417
}
402418

403419
private static ApiResponseType CreateDefaultApiResponseType(Type responseType)

0 commit comments

Comments
 (0)