-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
Priority:3Work that is nice to haveWork that is nice to havearea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routingfeature-openapiold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone
Description
Describe the bug
Attributes of parameters of Minimal Actions cannot be inspected in API Explorer as the ParameterDescriptor property of the ApiParameterDescription for the parameter is always null. Further, if it were not null, the type of the value of the property would need to implement IParameterInfoParameterDescriptor so that the relevant ParameterInfo value could be accessible for inspection.
aspnetcore/src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs
Lines 166 to 174 in e6a5af6
| return new ApiParameterDescription | |
| { | |
| Name = name, | |
| ModelMetadata = CreateModelMetadata(parameter.ParameterType), | |
| Source = source, | |
| DefaultValue = parameter.DefaultValue, | |
| Type = parameter.ParameterType, | |
| IsRequired = !isOptional | |
| }; |
To Reproduce
The following unit test demonstrates the issue, it fails due to nameParam.ParameterDescription being null.
[Fact]
public void TestParameterAttributesCanBeInspected()
{
var apiDescription = GetApiDescription(([Description("The name.")] string name) => { });
Assert.Equal(1, apiDescription.ParameterDescriptions.Count);
var nameParam = apiDescription.ParameterDescriptions[0];
Assert.Equal(typeof(string), nameParam.Type);
Assert.Equal(typeof(string), nameParam.ModelMetadata.ModelType);
Assert.Equal(BindingSource.Query, nameParam.Source);
Assert.False(nameParam.IsRequired);
Assert.NotNull(nameParam.ParameterDescriptor); // Assertion fails here
Assert.Equal("name", nameParam.ParameterDescriptor.Name);
Assert.Equal(typeof(string), nameParam.ParameterDescriptor.ParameterType);
var descriptor = Assert.IsAssignableFrom<IParameterInfoParameterDescriptor>(nameParam.ParameterDescriptor);
Assert.NotNull(descriptor.ParameterInfo);
var description = Assert.Single(descriptor.ParameterInfo.GetCustomAttributes<DescriptionAttribute>());
Assert.NotNull(description);
Assert.Equal("The name.", description.Description);
}Further technical details
Tested as of commit b33b4d4453d93be12a847a5e0c222d86edd706a0.
Metadata
Metadata
Assignees
Labels
Priority:3Work that is nice to haveWork that is nice to havearea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routingfeature-openapiold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels