Skip to content

Analyzers API1000 and API1001 should trigger on conditional returns #33105

Closed as not planned

Description

@eatdrinksleepcode

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
}

Activity

  1. added
    area-mvc
    on May 28, 2021
  2. pranavkm commented on May 28, 2021

    @pranavkm
    Contributor

    @eatdrinksleepcode I think rewriting these analyzers to use operation blocks should simplify authoring it and address a lot of these control-flow issues. Is that something you might be interested in trying to pick up?

  3. eatdrinksleepcode commented on May 29, 2021

    @eatdrinksleepcode
    ContributorAuthor

    Agreed, using operations makes more sense with these semantic rules. I can look into that this weekend. Should I open a separate issue?

  4. added
    good first issue
    help wanted
    analyzer
    on May 31, 2021
  5. added this to the Backlog milestone on Jun 1, 2021
  6. mkArtakMSFT commented on Jun 1, 2021

    @mkArtakMSFT
    Contributor

    Thanks for contacting us, @eatdrinksleepcode .
    Let's use this issue to track it. Send out the PR and we'll look at it.

  7. singh733 commented on Jun 21, 2021

    @singh733
    Contributor

    @pranavkm I have gone through the code and below is the proposed solution. Please see the TODO Comment :

    image

  8. Youssef1313 commented on Jul 17, 2021

    @Youssef1313
    Member

    @pranavkm I have gone through the code and below is the proposed solution. Please see the TODO Comment :

    image

    It's better to completely rewrite using IOperation rather than using syntax analysis.

  9. Youssef1313 commented on Jul 17, 2021

    @Youssef1313
    Member

    Looks like this was already rewritten in #34020.

    This will need a test to confirm whether this specific issue was fixed with the rewrite or not.

  10. eatdrinksleepcode commented on Jul 28, 2021

    @eatdrinksleepcode
    ContributorAuthor

    @Youssef1313 the code was rewritten to use operations instead of syntax, but conditional returns were not handled as far as I can see. The new code is still examining the return for method calls and object creation, not for conditionals.

  11. pranavkm commented on Jul 28, 2021

    @pranavkm
    Contributor

    Yup - it was straight rewrite without adding new features. If you'd like to extend it further, we'd be happy to accept a PR for it.

  12. added and removed
    help wanted
    on Oct 28, 2023
  13. added
    help wanted
    and removed on Jan 7, 2026
  14. added a commit that references this issue on Mar 20, 2026
    cc6f65f
  15. Youssef1313 commented on Aug 18, 2026

    @Youssef1313
    Member

    This analyzer was deprecated in .NET 10 and removed in .NET 11. See https://learn.microsoft.com/en-us/aspnet/core/breaking-changes/10/openapi-analyzers-deprecated

    Related to #68087

    cc @danroth27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    analyzerarea-mvcfeature-openapigood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions