ProducesResponseTypeAttribute(int statusCode) ctor added
Addresses #4863
This commit is contained in:
parent
d5b0ebd10c
commit
79e576b86c
|
|
@ -13,6 +13,15 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
|
||||
public class ProducesResponseTypeAttribute : Attribute, IApiResponseMetadataProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes an instance of <see cref="ProducesResponseTypeAttribute"/>.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">The HTTP response status code.</param>
|
||||
public ProducesResponseTypeAttribute(int statusCode)
|
||||
: this(typeof(void), statusCode)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an instance of <see cref="ProducesResponseTypeAttribute"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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<Type, string, List<FilterDescriptor>>
|
||||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue