Closed
Description
When using the ApiExplorer in AspNet Core a null reference exception is thrown if the API defines a parameter as part of a route, but does not have matching parameter on the controller method.
[HttpGet("foo/{unmatched}"]
public string GetFoo()
{
return "foo";
}
With no matching C# parameter on GetFoo() the ApiParameterDescription's ModelMetadata is null. A null coalescing operator should fix the problem.
void RemoveAllParametersExcept( ApiParameterDescription parameter )
{
// code omitted
if ( otherParameter?.ModelMetadata.DataTypeName == nameof( ApiVersion ) )
{
collection.Remove( otherParameter );
}
// code omitted
}