Skip to content

Create an analyzer to detect mismatched parameter optionality #34553

Closed
Listed in
@captainsafia

Description

@captainsafia

As a follow-up to the work completed in #34505, we should add support for labeling optional parameters in a route using the route string. For example:

app.MapGet("/action/{foo?}", (string? foo) => ...)

Will treat the foo parameter as optional in the endpoint above. For scenarios where the optionality defined in the route and the optionality defined in the method differ, then we will throw an exception. For example, the route string below defines a parameter as optional but the method defines it as required:

app.MapGet("/action/{foo?}", (string foo) => ...);

This feature can be achieved by examining the values of factoryContext.RouteParameterNames and factoring it into the data binding done in BindParametersFromQueryOrRouteValue.

Activity

added
enhancementThis issue represents an ask for new feature or an enhancement to an existing one
on Jul 20, 2021
added this to the 6.0-rc2 milestone on Jul 20, 2021
added
area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates
on Jul 21, 2021
captainsafia

captainsafia commented on Aug 2, 2021

@captainsafia
MemberAuthor

Note: as part of this we should also validate how this behaves in swagger. See more info at https://gist.github.com/rafikiassumaniMSFT/52f9a6f9d005a38b668315d4f7db262b#gistcomment-3840821

captainsafia

captainsafia commented on Aug 24, 2021

@captainsafia
MemberAuthor

Following a recent discussion, we've decided that for this issue, we are going to focus on writing a set of analyzers to alert users about problematic scenarios. The analyzer + codefix will instruct users to add the optionality flag to the arguments in addition to the route param.

changed the title [-]Support route parameter optionality via route string[/-] [+]Create an analyzer to detect mismatched parameter optionality[/+] on Aug 26, 2021
ghost locked as resolved and limited conversation to collaborators on Oct 10, 2021
added
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
on Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-minimal-actionsController-like actions for endpoint routing

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @Pilchie@captainsafia@amcasey

      Issue actions

        Create an analyzer to detect mismatched parameter optionality · Issue #34553 · dotnet/aspnetcore