Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an analyzer to detect mismatched parameter optionality #34553

Closed
Tracked by #35528
captainsafia opened this issue Jul 20, 2021 · 2 comments
Closed
Tracked by #35528

Create an analyzer to detect mismatched parameter optionality #34553

captainsafia opened this issue Jul 20, 2021 · 2 comments
Assignees
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-minimal-actions Controller-like actions for endpoint routing
Milestone

Comments

@captainsafia
Copy link
Member

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.

@captainsafia captainsafia added enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-minimal-actions Controller-like actions for endpoint routing labels Jul 20, 2021
@captainsafia captainsafia added this to the 6.0-rc2 milestone Jul 20, 2021
@Pilchie Pilchie added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jul 21, 2021
@captainsafia
Copy link
Member Author

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
Copy link
Member Author

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.

@captainsafia captainsafia changed the title Support route parameter optionality via route string Create an analyzer to detect mismatched parameter optionality Aug 26, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Oct 10, 2021
@amcasey amcasey added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-minimal-actions Controller-like actions for endpoint routing
Projects
None yet
Development

No branches or pull requests

3 participants