parent
5a20037965
commit
e2b6f07778
|
|
@ -26,6 +26,7 @@ namespace Microsoft.AspNetCore.Mvc.ApiExplorer
|
||||||
private readonly MvcOptions _mvcOptions;
|
private readonly MvcOptions _mvcOptions;
|
||||||
private readonly IActionResultTypeMapper _mapper;
|
private readonly IActionResultTypeMapper _mapper;
|
||||||
private readonly ApiResponseTypeProvider _responseTypeProvider;
|
private readonly ApiResponseTypeProvider _responseTypeProvider;
|
||||||
|
private readonly RouteOptions _routeOptions;
|
||||||
private readonly IInlineConstraintResolver _constraintResolver;
|
private readonly IInlineConstraintResolver _constraintResolver;
|
||||||
private readonly IModelMetadataProvider _modelMetadataProvider;
|
private readonly IModelMetadataProvider _modelMetadataProvider;
|
||||||
|
|
||||||
|
|
@ -53,6 +54,7 @@ namespace Microsoft.AspNetCore.Mvc.ApiExplorer
|
||||||
/// constraints.</param>
|
/// constraints.</param>
|
||||||
/// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param>
|
/// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param>
|
||||||
/// <param name="mapper"> The <see cref="IActionResultTypeMapper"/>.</param>
|
/// <param name="mapper"> The <see cref="IActionResultTypeMapper"/>.</param>
|
||||||
|
[Obsolete("This constructor is obsolete and will be removed in a future release.")]
|
||||||
public DefaultApiDescriptionProvider(
|
public DefaultApiDescriptionProvider(
|
||||||
IOptions<MvcOptions> optionsAccessor,
|
IOptions<MvcOptions> optionsAccessor,
|
||||||
IInlineConstraintResolver constraintResolver,
|
IInlineConstraintResolver constraintResolver,
|
||||||
|
|
@ -66,6 +68,30 @@ namespace Microsoft.AspNetCore.Mvc.ApiExplorer
|
||||||
_responseTypeProvider = new ApiResponseTypeProvider(modelMetadataProvider, mapper, _mvcOptions);
|
_responseTypeProvider = new ApiResponseTypeProvider(modelMetadataProvider, mapper, _mvcOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new instance of <see cref="DefaultApiDescriptionProvider"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="optionsAccessor">The accessor for <see cref="MvcOptions"/>.</param>
|
||||||
|
/// <param name="constraintResolver">The <see cref="IInlineConstraintResolver"/> used for resolving inline
|
||||||
|
/// constraints.</param>
|
||||||
|
/// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param>
|
||||||
|
/// <param name="mapper"> The <see cref="IActionResultTypeMapper"/>.</param>
|
||||||
|
/// <param name="routeOptions">The accessor for <see cref="RouteOptions"/>.</param>
|
||||||
|
public DefaultApiDescriptionProvider(
|
||||||
|
IOptions<MvcOptions> optionsAccessor,
|
||||||
|
IInlineConstraintResolver constraintResolver,
|
||||||
|
IModelMetadataProvider modelMetadataProvider,
|
||||||
|
IActionResultTypeMapper mapper,
|
||||||
|
IOptions<RouteOptions> routeOptions)
|
||||||
|
{
|
||||||
|
_mvcOptions = optionsAccessor.Value;
|
||||||
|
_constraintResolver = constraintResolver;
|
||||||
|
_modelMetadataProvider = modelMetadataProvider;
|
||||||
|
_mapper = mapper;
|
||||||
|
_responseTypeProvider = new ApiResponseTypeProvider(modelMetadataProvider, mapper, _mvcOptions);
|
||||||
|
_routeOptions = routeOptions.Value;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public int Order => -1000;
|
public int Order => -1000;
|
||||||
|
|
||||||
|
|
@ -383,7 +409,9 @@ namespace Microsoft.AspNetCore.Mvc.ApiExplorer
|
||||||
{
|
{
|
||||||
if (part.IsLiteral)
|
if (part.IsLiteral)
|
||||||
{
|
{
|
||||||
currentSegment += part.Text;
|
currentSegment += _routeOptions.LowercaseUrls ?
|
||||||
|
part.Text.ToLowerInvariant() :
|
||||||
|
part.Text;
|
||||||
}
|
}
|
||||||
else if (part.IsParameter)
|
else if (part.IsParameter)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -387,6 +387,25 @@ namespace Microsoft.AspNetCore.Mvc.Description
|
||||||
Assert.Single(description.ParameterDescriptions, p => p.Name == "id5");
|
Assert.Single(description.ParameterDescriptions, p => p.Name == "id5");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetApiDescription_ProducesLowerCaseRelativePaths()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var action = CreateActionDescriptor();
|
||||||
|
action.AttributeRouteInfo = new AttributeRouteInfo
|
||||||
|
{
|
||||||
|
Template = "api/Products/UpdateProduct/{productId}"
|
||||||
|
};
|
||||||
|
var routeOptions = new RouteOptions { LowercaseUrls = true };
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var descriptions = GetApiDescriptions(action, routeOptions: routeOptions);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var description = Assert.Single(descriptions);
|
||||||
|
Assert.Equal("api/products/updateproduct/{productId}", description.RelativePath);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GetApiDescription_PopulatesResponseType_WithProduct()
|
public void GetApiDescription_PopulatesResponseType_WithProduct()
|
||||||
{
|
{
|
||||||
|
|
@ -1797,7 +1816,8 @@ namespace Microsoft.AspNetCore.Mvc.Description
|
||||||
ActionDescriptor action,
|
ActionDescriptor action,
|
||||||
List<MockInputFormatter> inputFormatters = null,
|
List<MockInputFormatter> inputFormatters = null,
|
||||||
List<MockOutputFormatter> outputFormatters = null,
|
List<MockOutputFormatter> outputFormatters = null,
|
||||||
bool allowValidatingTopLevelNodes = true)
|
bool allowValidatingTopLevelNodes = true,
|
||||||
|
RouteOptions routeOptions = null)
|
||||||
{
|
{
|
||||||
var context = new ApiDescriptionProviderContext(new ActionDescriptor[] { action });
|
var context = new ApiDescriptionProviderContext(new ActionDescriptor[] { action });
|
||||||
|
|
||||||
|
|
@ -1827,7 +1847,8 @@ namespace Microsoft.AspNetCore.Mvc.Description
|
||||||
optionsAccessor,
|
optionsAccessor,
|
||||||
constraintResolver.Object,
|
constraintResolver.Object,
|
||||||
modelMetadataProvider,
|
modelMetadataProvider,
|
||||||
new ActionResultTypeMapper());
|
new ActionResultTypeMapper(),
|
||||||
|
Options.Create(routeOptions ?? new RouteOptions()));
|
||||||
|
|
||||||
provider.OnProvidersExecuting(context);
|
provider.OnProvidersExecuting(context);
|
||||||
provider.OnProvidersExecuted(context);
|
provider.OnProvidersExecuted(context);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue