dotnet / dotnet/aspnetcore

OpenApi analyzers do not recognize returns in ternary expressions

Open
#43,356 1 comment 0 reactions 0 assignees View on GitHub
analyzer area-mvc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

I enabled web API analyzers per [the docs](https://docs.microsoft.com/en-us/aspnet/core/web-api/advanced/analyzers) and was surprised to see no output. Long story short, the analyzer does not recognize returns in ternary expressions. All my controllers return like this:

```C#
return result != null ? Ok(result) : NotFound();
```

If I change this to an `if` expression, the analyzer highlights `NotFound()` and emits a warning as expected. But even then, it still does not warn that I have not documented what `Ok()` returns. I'm not sure if it's supposed to.

This may have been the issue underlying #26341.

### Expected Behavior

_No response_

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

6.0.400

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.