Skip to content

Create an analyzer to detect mismatched parameter optionality #34553

@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.

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

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions