Skip to content

Commit aa948cb

Browse files
committed
Support setting content types in ProducesResponseTypeAttribute to close #34542
1 parent ac3a403 commit aa948cb

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Mvc/Mvc.Core/src/ProducesResponseTypeAttribute.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public ProducesResponseTypeAttribute(Type type, int statusCode)
3333
Type = type ?? throw new ArgumentNullException(nameof(type));
3434
StatusCode = statusCode;
3535
IsResponseTypeSetByDefault = false;
36+
ContentTypes = new();
3637
}
3738

3839
/// <summary>
@@ -45,6 +46,11 @@ public ProducesResponseTypeAttribute(Type type, int statusCode)
4546
/// </summary>
4647
public int StatusCode { get; set; }
4748

49+
/// <summary>
50+
/// Gets or sets the content types supported by the response.
51+
/// </summary>
52+
public MediaTypeCollection ContentTypes { get; set; }
53+
4854
/// <summary>
4955
/// Used to distinguish a `Type` set by default in the constructor versus
5056
/// one provided by the user.
@@ -58,9 +64,9 @@ public ProducesResponseTypeAttribute(Type type, int statusCode)
5864
internal bool IsResponseTypeSetByDefault { get; }
5965

6066
/// <inheritdoc />
61-
void IApiResponseMetadataProvider.SetContentTypes(MediaTypeCollection contentTypes)
67+
public void SetContentTypes(MediaTypeCollection contentTypes)
6268
{
63-
// Users are supposed to use the 'Produces' attribute to set the content types that an action can support.
69+
ContentTypes = contentTypes;
6470
}
6571
}
6672
}

0 commit comments

Comments
 (0)