-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
ApiExplorer not handling multiple routes on same action method correctly #26234
Comments
Here's the corresponding downstream issue that was originally created in Swashbuckle.AspNetCore: |
In the meantime, if you're really stuck you could wire up an |
I had the filter look at ApiDescription.ParamaterDescriptions, and if In==Path and !IsRequired, removed it from the operation.Parameters list. I don't know that this will work for every case, but it was enough for my routes. |
Thanks for contacting us. |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
@domaindrivendev the short answer for that is, you could workaround it by setting builder.Services.Configure<ApiBehaviorOptions>(options => {
options.SuppressInferBindingSourcesForParameters = true;
}); Now, to give you more details. When your controller is annotated with As you can see, in your case you do have a route where the parameter is included in the route, that means this parameter will be inferred as Once you have the property {
"openapi": "3.0.1",
"info": {
"title": "OpenAPISample",
"version": "1.0"
},
"paths": {
"/WeatherForecast/foo": {
"get": {
"tags": [
"WeatherForecast"
],
"operationId": "Foo",
"parameters": [
{
"name": "id",
"in": "query",
"schema": {
"type": "integer",
"format": "int32",
"default": 0
}
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/WeatherForecast/bar/{id}": {
"get": {
"tags": [
"WeatherForecast"
],
"operationId": "Bar",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32",
"default": 0
}
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
}
},
"components": { }
} Just remind that it is a global configuration that will affect all API controllers that might cause some issues to your current APIs. |
@domaindrivendev In addition to my previous comment, it is a bug and it should be work correct without you need to change the |
Doesn't this change the actual behavior of the controller and not just the ApiExplorer model? Based on the linked docs, I would expect that the |
@halter73, exactly that is why I included a small disclaimer (below) at the end. However, I tested it and the parameter binding still working, without adding the attributes, for me but I did not check exactly why. |
Describe the bug
Given the following action method bound to multiple routes:
As expected, the ApiExplorer surfaces two
ApiDescription
instances, one for each route. However, for the first route "foo", theApiDescription
includes theid
path parameter, despite the fact that it's not part of the route template. For example, here's the ApiExplorer data (serialized as json):To Reproduce
Further technical details
The text was updated successfully, but these errors were encountered: