Describe the bug
Analyzers API1000 and API1001 do not trigger on expression-bodied members, while they do trigger on the equivalent block-bodied members.
To Reproduce
[ProducesResponseType(statusCode: Status400BadRequest)]
public ActionResult<string> OopsUndocumented()
{
return Unauthorized(); // API1000
}
[ProducesResponseType(statusCode: Status400BadRequest)]
public ActionResult<string> OopsUndocumentedExpression() => Unauthorized(); // No API1000
[ProducesResponseType(statusCode: Status400BadRequest)]
public ActionResult<string> OopsUndocumentedSuccess()
{
return ""; // API1001
}
[ProducesResponseType(statusCode: Status400BadRequest)]
public ActionResult<string> OopsUndocumentedSuccessExpression() => ""; // No API1001
Cause
This is due to ActualApiResponseMetadataFactory.TryGetActualResponseMetadata only looking for ReturnStatementSyntax nodes (code). In an expression-bodied member, there is no return; you have to examine the ExpressionBody property of the MethodDeclarationSyntax.
Further technical details
- ASP.NET Core version: 5.0.202
Describe the bug
Analyzers API1000 and API1001 do not trigger on expression-bodied members, while they do trigger on the equivalent block-bodied members.
To Reproduce
Cause
This is due to
ActualApiResponseMetadataFactory.TryGetActualResponseMetadataonly looking forReturnStatementSyntaxnodes (code). In an expression-bodied member, there is noreturn; you have to examine theExpressionBodyproperty of theMethodDeclarationSyntax.Further technical details