dotnet/aspnetcore

Analyzers API1000 and API1001 should trigger on conditional returns

Open

#33,105 opened on May 28, 2021

View on GitHub
 (9 comments) (2 reactions) (0 assignees)C# (10,653 forks)batch import
analyzerarea-mvcfeature-openapigood first issuehelp wanted

Repository metrics

Stars
 (37,933 stars)
PR merge metrics
 (Avg merge 16d 9h) (258 merged PRs in 30d)

Description

Describe the solution you'd like

Analyzers API1000 and API1001 should trigger on returns (or expression-bodied methods) with conditional expressions.

Additional context

public ActionResult<object> OopsUndocumentedIf(int id)
{
    if (id == 0)
    {
        return NotFound(); // API1000
    }

    return Ok(new object());
}

public ActionResult<object> OopsUndocumentedConditional(int id)
{
    return id == 0 ? NotFound() : Ok(new object()); // No API1000
}

Contributor guide