Aggregate multiple Produces
for same status code but different content-types
#56177
Open
1 task done
Labels
area-minimal
Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
area-mvc
Includes: MVC, Actions and Controllers, Localization, CORS, most templates
feature-openapi
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
OpenApi v3.0 and later can describe multiple response "contents" for a single status code differentiated by the response content-type. Each "contents" definition can have its own schema. A common case may be:
Currently this response description can't be created just using
Produces
because each produces can specify only one response type (schema), so twoProduces
are needed for the case above, but the secondProduces
for a given status code overrides the information of the first, even if it is for a distinct content type.Implementation Plan For Copilot
We need to add support for multiple response types with the same status code in ApiExplorer. This limitation currently exists because our ApiResponseTypeProvider only maintains a list of types based on status code. When two attributes specify the same code, the second entry overrides the first. This happens in
ApiResponseTypeProvider.ReadResponseMetadata
. We need to update the code to support deduplicating based on status-code and content-type.The relevant files are:
ApiResponseTypeProvider.cs
ApiResponseMetadataProviderContext.cs
ApiResponseTypeProviderTest.cs
We should solve this by completing the following steps:
Add a compound key record
Replace the status-code dictionary in ApiResponseTypeProvider
Build a key for every discovered response
Optional: if true duplicates arise (same code + type + content type) you may merge their
ContentTypes
collections instead of discarding either.Populate
SupportedResponseTypes
(Nice-to-have) deterministic ordering
Unit tests
[ProducesResponseType]
attributes with identical status code but distinct content-types types ➜ assertSupportedResponseTypes.Count == 2
.ContentTypes
merging logic if implemented.Produces
calls on minimal API with identical status codes and different content-types produces multiple responses.The text was updated successfully, but these errors were encountered: