diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ProducesResponseTypeAttribute.cs b/src/Microsoft.AspNetCore.Mvc.Core/ProducesResponseTypeAttribute.cs
index 126310817c..7c0d25c6a4 100644
--- a/src/Microsoft.AspNetCore.Mvc.Core/ProducesResponseTypeAttribute.cs
+++ b/src/Microsoft.AspNetCore.Mvc.Core/ProducesResponseTypeAttribute.cs
@@ -13,6 +13,15 @@ namespace Microsoft.AspNetCore.Mvc
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class ProducesResponseTypeAttribute : Attribute, IApiResponseMetadataProvider
{
+ ///
+ /// Initializes an instance of .
+ ///
+ /// The HTTP response status code.
+ public ProducesResponseTypeAttribute(int statusCode)
+ : this(typeof(void), statusCode)
+ {
+ }
+
///
/// Initializes an instance of .
///
diff --git a/test/Microsoft.AspNetCore.Mvc.ApiExplorer.Test/DefaultApiDescriptionProviderTest.cs b/test/Microsoft.AspNetCore.Mvc.ApiExplorer.Test/DefaultApiDescriptionProviderTest.cs
index e58a76610e..07a84637a7 100644
--- a/test/Microsoft.AspNetCore.Mvc.ApiExplorer.Test/DefaultApiDescriptionProviderTest.cs
+++ b/test/Microsoft.AspNetCore.Mvc.ApiExplorer.Test/DefaultApiDescriptionProviderTest.cs
@@ -423,12 +423,15 @@ namespace Microsoft.AspNetCore.Mvc.Description
new FilterDescriptor(
new ProducesAttribute("text/json", "application/json") { Type = typeof(Customer) },
FilterScope.Action),
+ new FilterDescriptor(
+ new ProducesResponseTypeAttribute(304),
+ FilterScope.Action),
new FilterDescriptor(
new ProducesResponseTypeAttribute(typeof(BadData), 400),
FilterScope.Action),
new FilterDescriptor(
new ProducesResponseTypeAttribute(typeof(ErrorDetails), 500),
- FilterScope.Action)
+ FilterScope.Action),
};
return new TheoryData>
@@ -443,11 +446,16 @@ namespace Microsoft.AspNetCore.Mvc.Description
nameof(DefaultApiDescriptionProviderTest.ReturnsActionResult),
filterDescriptors
},
+ {
+ typeof(DefaultApiDescriptionProviderTest),
+ nameof(DefaultApiDescriptionProviderTest.ReturnsActionResult),
+ filterDescriptors
+ },
{
typeof(DerivedProducesController),
nameof(DerivedProducesController.ReturnsActionResult),
filterDescriptors
- },
+ }
};
}
}
@@ -469,7 +477,7 @@ namespace Microsoft.AspNetCore.Mvc.Description
// Assert
var description = Assert.Single(descriptions);
- Assert.Equal(3, description.SupportedResponseTypes.Count);
+ Assert.Equal(4, description.SupportedResponseTypes.Count);
Assert.Collection(
description.SupportedResponseTypes.OrderBy(responseType => responseType.StatusCode),
@@ -481,6 +489,13 @@ namespace Microsoft.AspNetCore.Mvc.Description
Assert.Equal(expectedMediaTypes, GetSortedMediaTypes(responseType));
},
responseType =>
+ {
+ Assert.Equal(304, responseType.StatusCode);
+ Assert.Equal(typeof(void), responseType.Type);
+ Assert.Null(responseType.ModelMetadata);
+ Assert.Empty(responseType.ApiResponseFormats);
+ },
+ responseType =>
{
Assert.Equal(400, responseType.StatusCode);
Assert.Equal(typeof(BadData), responseType.Type);
@@ -509,7 +524,7 @@ namespace Microsoft.AspNetCore.Mvc.Description
new ProducesAttribute("text/json", "application/json"),
FilterScope.Action),
new FilterDescriptor(
- new ProducesResponseTypeAttribute(typeof(void), 200),
+ new ProducesResponseTypeAttribute(200),
FilterScope.Action),
new FilterDescriptor(
new ProducesResponseTypeAttribute(typeof(BadData), 400),
diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ProducesAttributeTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ProducesAttributeTests.cs
index 4c57efd1a2..8ae4563270 100644
--- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ProducesAttributeTests.cs
+++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ProducesAttributeTests.cs
@@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Mvc.Test
() => new ProducesAttribute(contentTypes[0], contentTypes.Skip(1).ToArray()));
Assert.Equal(
- string.Format("The argument '{0}' is invalid. "+
+ string.Format("The argument '{0}' is invalid. " +
"Media types which match all types or match all subtypes are not supported.",
invalidContentType),
ex.Message);