Closed
Listed in
Description
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
Type
Projects
Relationships
Development
No branches or pull requests
Activity
captainsafia commentedon Aug 2, 2021
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 commentedon Aug 24, 2021
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.
[-]Support route parameter optionality via route string[/-][+]Create an analyzer to detect mismatched parameter optionality[/+]