Support conditional expressions in API1000/API1001 analyzers#65893
Open
luissena wants to merge 1 commit intodotnet:mainfrom
Open
Support conditional expressions in API1000/API1001 analyzers#65893luissena wants to merge 1 commit intodotnet:mainfrom
luissena wants to merge 1 commit intodotnet:mainfrom
Conversation
The API convention analyzers (API1000 and API1001) did not inspect conditional (ternary) expressions, so undocumented status codes in returns like `return id == 0 ? NotFound() : Ok()` went undetected. This change extends `InspectReturnOperation` in `ActualApiResponseMetadataFactory` to recurse into both branches of `IConditionalOperation`, matching the existing pattern used for `ISwitchExpressionOperation`. The `ISwitchExpressionArmOperation?` parameter was generalized to `IOperation?` to support passing branch values from both switch arms and conditional expressions through the same code path. Fixes dotnet#33105
Contributor
|
Thanks for your PR, @@luissena. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
This was referenced Mar 21, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #33105
The API convention analyzers (
API1000andAPI1001) did not inspect conditional (ternary) expressions, causing undocumented status codes to go undetected in return statements like:While
if/elseandswitchexpressions were already handled, conditional expressions were silently skipped.Changes
InspectReturnOperationinActualApiResponseMetadataFactoryto recurse into both branches (WhenTrue/WhenFalse) ofIConditionalOperation, following the same pattern already used forISwitchExpressionOperationISwitchExpressionArmOperation?parameter toIOperation?so both switch arm values and conditional branch values flow through the same code pathNoDiagnosticsAreReturned_ForApiController_IfStatusCodesCannotBeInferred) — now that conditionals are inspected, the analyzer correctly reports undocumented status codesTest plan
a ? b : c) correctly produceAPI1000diagnostics for undocumented status codesa ? b : c ? d : e) correctly produce diagnostics for all branchesif/else,switch, andswitch expressiontest coverage