Skip to content

[Analyzer] Unused route parameter detection and fixer #44319

@JamesNK

Description

@JamesNK

Background and Motivation

When adding a route parameter to a minimal API or action:

  1. The route parameter needs to be added to the route
  2. .NET parameter needs to be added to the lambda/method.

An analyzer and fixer can automate step 2.

Proposed API

An analyzer inspects the route for route parameters and the lambda/action parameters. If the route has a parameter that isn't present in the lambda/action then the analyzer will suggest a fix.

  • Suggestion level (it's valid to have a route parameter that's not used so this isn't a warning)
  • Optional route parameter = nullable argument
  • Route parameter constraint is used to infer the .NET type. e.g. int constraint = int method parameter. Same with guid, int, long, double, float, datetime, decimal, etc. No route parameter means the new parameter type is string.
  • Put the new parameter in the method based on its position in the route.

Usage Examples

MicrosoftTeams-image

Alternative Designs

Risks

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implemented

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions