Skip to content

Commit 9fff552

Browse files
Copilotcaptainsafia
andcommitted
Support multiple content types with same status code in OpenApiDocumentService
Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
1 parent cc6728c commit 9fff552

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/OpenApi/src/Services/OpenApiDocumentService.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,26 @@ private async Task<OpenApiResponses> GetResponsesAsync(
386386
var responseKey = responseType.IsDefaultResponse
387387
? OpenApiConstants.DefaultOpenApiResponseKey
388388
: responseType.StatusCode.ToString(CultureInfo.InvariantCulture);
389-
responses.Add(responseKey, await GetResponseAsync(document, description, responseType.StatusCode, responseType, scopedServiceProvider, schemaTransformers, cancellationToken));
389+
390+
if (responses.TryGetValue(responseKey, out var existingResponse))
391+
{
392+
// If a response with the same status code already exists, add the content types
393+
// from the current responseType to the existing response's Content dictionary
394+
var newResponse = await GetResponseAsync(document, description, responseType.StatusCode, responseType, scopedServiceProvider, schemaTransformers, cancellationToken);
395+
396+
if (newResponse.Content != null && existingResponse.Content != null)
397+
{
398+
foreach (var contentType in newResponse.Content)
399+
{
400+
existingResponse.Content.TryAdd(contentType.Key, contentType.Value);
401+
}
402+
}
403+
}
404+
else
405+
{
406+
// Add new response
407+
responses.Add(responseKey, await GetResponseAsync(document, description, responseType.StatusCode, responseType, scopedServiceProvider, schemaTransformers, cancellationToken));
408+
}
390409
}
391410
return responses;
392411
}

0 commit comments

Comments
 (0)