Skip to content

Analyzers API1000 and API1001 do not trigger on expression-bodied members #33091

@eatdrinksleepcode

Description

@eatdrinksleepcode

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    analyzerIndicates an issue which is related to analyzer experiencearea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing one

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions