Client generated code, from OpenAPI, could not bind route parameter of a Minimal Endpoint when route pattern's parameter and delegate's parameter case does not match #41422
Labels
area-minimal
Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
area-web-frameworks
*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
bug
This issue describes a behavior which is not expected - a bug.
feature-minimal-actions
Controller-like actions for endpoint routing
feature-openapi
Milestone
Is there an existing issue for this?
Describe the bug
When I have a minimal endpoint
route pattern
that includes aroute parameter
that does not match the delegate parameter name case, eg.:The route system will be able to bind the parameter value correctly, since it is
case insensitive
and all incoming request will be processed correctly.aspnetcore/src/Http/Routing/src/Patterns/RoutePattern.cs
Line 146 in 4b51476
However, when the
OpenAPI
metadata is enabled, the following metadata is generated, where the parameter name matches the delegate parameter name case instead of theroute parameter
.This behavior might seem irrelevant and undetectable, however, when the Open API metadata is used in a client generation tool, eg.
VS Connected Service
s tool or evenSwagger UI
, this error will cause the client to no provide the route parameter value correctly, causing the following issue because the request url will be something likehttp://server:port/todo/{id}
since the generated code is not able to replace the {id} with the provided value.The following block of code is an example of the client generated code where the request url is build and fail to replace the placeholder with the appropriated value.
This error could be easily fixed by changing the delegate's parameter or route pattern's parameter case, however, as mentioned the error is undetectable and only the client generation will be affected. Another important point is that this error will be more likely to happen when #40712 is available
Expected Behavior
Since the routing system is case insensitive already, I would expect that the following endpoints produce the same metadata:
If the correct metadata generation is not possible, we should at least have the tool available in Visual Studio able to generate a client capable of binding the route parameter value correctly.
Steps To Reproduce
Server
Program.cs
Client
While running the server application, collect the metadata json file and try to create the generated client with the following steps:
Add a service reference from OpenAPI
Specify the required information for the reference
Add the following code to your app
Exceptions (if any)
.NET Version
7.0.100-preview.4.22218.7
Anything else?
N/A
The text was updated successfully, but these errors were encountered: