dotnet/aspnetcore

Analyzers API1000 and API1001 should trigger on conditional returns

Chiusa

#33.105 aperta il 28 mag 2021

 (9 commenti) (2 reazioni) (0 assegnatari)C# (10.653 fork)batch import
analyzerarea-mvcfeature-openapigood first issuehelp wanted

Metriche repository

Star
 (37.933 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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
}

Guida contributor