Add generic ConsumesAttribute<T> - #69017
Draft
campersau wants to merge 1 commit into
Draft
Conversation
Adds a generic ConsumesAttribute<T>, mirroring the existing ProducesResponseTypeAttribute<T> pattern, so the request type can be specified with compile-time type safety instead of via [Consumes(typeof(T), ...)]. Existing tests that exercised ConsumesAttribute with an explicit request type (EndpointMetadataApiDescriptionProviderTest, OpenApiDocumentServiceTests, OpenApiGeneratorTests) are updated to use the new Consumes<T> syntax, confirming the generic form behaves the same as the non-generic one. Fixes dotnet#67701 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G6qhxdfagHUri2p6icypbT
campersau
requested review from
a team,
Youssef1313,
cincuranet,
davpetr,
halter73 and
rokonec
as code owners
September 3, 2026 08:27
Contributor
|
Thanks for your PR, @campersau. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Youssef1313
requested changes
Sep 3, 2026
Youssef1313
left a comment
Member
There was a problem hiding this comment.
Thanks for the contribution @campersau.
We will need to review the API proposal first before moving forward. So, marking request changes until the API is reviewed/approved.
Member
@Youssef1313 can you make this PR a draft also? (I don't have rights for this). |
campersau
marked this pull request as draft
September 3, 2026 09:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a generic ConsumesAttribute
Description
Adds
ConsumesAttribute<T>, a generic variant ofConsumesAttributethat lets the request type be specified as a type parameter instead of through theType requestTypeconstructor overload, mirroring the existingProducesResponseTypeAttribute<T>pattern:ConsumesAttribute<T>inherits fromConsumesAttributeand forwards to the existingConsumesAttribute(Type requestType, string contentType, params string[] otherContentTypes)constructor withtypeof(T). It automatically picks up the base class's[AttributeUsage(Class | Method)]as well asIAcceptsMetadata/IConsumesActionConstraintbehavior, so no additional wiring is needed for either MVC controllers or minimal API endpoints.No new tests were added. Instead, existing tests that already exercised
ConsumesAttributewith an explicit request type were updated to use the newConsumes<T>syntax, which confirms the generic form behaves identically to the non-generic one:EndpointMetadataApiDescriptionProviderTestOpenApiDocumentServiceTests.RequestBodyOpenApiGeneratorTestsFixes #67701