Skip to content

Type mismatches between parameter and route constraints not caught #36859

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

Open
captainsafia opened this issue Sep 22, 2021 · 3 comments
Open
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-actions Controller-like actions for endpoint routing feature-routing
Milestone

Comments

@captainsafia
Copy link
Member

captainsafia commented Sep 22, 2021

In .NET 6, we added support for an analyzer that would detect the incompat between optionality annotations on the route constraint and parameter optionality in a minimal endpoint. See #34553 for more info.

We don't currently do anything about mismatches in the type constraints between a route and parameter, so having an endpoint like:

app.MapGet("/workouts/{id:int}", async (string id, IWorkoutsService workouts) => {
    return await workouts.GetItemAsync(id);
})

Will compile and build fine but sending the following request:

$ http http://localhost:5000/workouts/thisisastring

Will result in a 404 during the route matching phase without any warning to the user.

@captainsafia captainsafia added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Sep 22, 2021
@BrennanConroy BrennanConroy added this to the .NET 7 Planning milestone Sep 23, 2021
@rafikiassumani-msft rafikiassumani-msft added feature-minimal-actions Controller-like actions for endpoint routing feature-routing labels Dec 27, 2021
@ghost
Copy link

ghost commented Oct 11, 2022

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@captainsafia
Copy link
Member Author

@JamesNK Is this something the new routing tooling addresses?

@JamesNK
Copy link
Member

JamesNK commented Oct 12, 2022

It doesn't right now. But the route tooling infrastructure should make this analyzer quick to write:

  1. Query analyzers from route parser.
  2. Get a list of all parameters from usage context.
  3. Compare and report warnings as needed.

@amcasey amcasey added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Jun 2, 2023
@captainsafia captainsafia removed the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Jun 6, 2023
@captainsafia captainsafia modified the milestones: .NET 8 Planning, Backlog Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-actions Controller-like actions for endpoint routing feature-routing
Projects
None yet
Development

No branches or pull requests

5 participants