-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
The method 'Post' on path '/api/admin/v/product' is registered multiple times #1242
Comments
You don't need to add the ApiVersionProcessor because it is added by default. Otherwise I have to reproduce this first... |
I removed this line and the problem still exist: settings.GeneratorSettings.OperationProcessors.Insert(0, new ApiVersionProcessor()); I have another controller that looks like duplicating the given controller. However Swagger used to work when both Controllers coexist. Another controller is defined below. [Authorize]
[ApiVersion("1.0")]
[Route("api/admin/v{version:apiVersion}/product")]
[TypeFilter(typeof(UserAccessFilter))]
[ServiceFilter(typeof(LanguageActionFilter))]
[ValidateModel]
public class ProductController : ApiController
{
public ProductController ()
{
}
[HttpPost]
[Authorize("product.create")]
[Route("")]
[ProducesResponseType(200, Type = typeof(Product))]
[ProducesResponseType(400, Type = typeof(OperationError))]
public async Task<IActionResult> Create([FromBody] ProductCreateRequest p)
{//
}
[HttpPut]
[Authorize("product.edit")]
[Route("{productId:int}")]
[ProducesResponseType(200, Type = typeof(Product))]
[ProducesResponseType(400, Type = typeof(OperationError))]
public async Task<IActionResult> Update(int productId, [FromBody] ProductUpdateRequest p)
{//
}
} |
Maybe the other controller is interfering... try adding SwaggerIgnoreAttribute to one of them to see if this is the problem... |
I received a similar error message. I added NSwag to asp.net core 2 / angular 2 project template. Then added a new web api controller and angular code. Everything worked. I then performed the steps to integrated nswag. Note: I changed the default route rule... changed 'id' to 'locale'. The website worked fine with this change. Going to http://localhost:50895/swagger/v1/swagger.json returned this error:
When I added [SwaggerIgnoreAttribute] to the HomeController, then NSwag worked. Questions:
I was able to freely define route variable names for api routes. Startup.cs
visual studio 2017 |
My mistake. I missed this setting: settings.GeneratorSettings.DefaultUrlTemplate
|
Ok. I just tried adding
|
Hi, @RSuter , I have solved the problem that is interesting and nice to inform you. public abstract class ApiController : ControllerBase
{
protected IActionResult ApiResponse<T>(Result<T> result)
{
return result.Match<IActionResult>(
Succ: domain => Ok(domain),
Fail: HandleBadRequest
);
}
public IActionResult HandleBadRequest(Exception ex) // here is the problematic code
{
return ex
.Match<IActionResult>()
.With<BusinessException>(BadRequest)
.Otherwise(e =>
{
LogError(e);
return BadRequest(new UnknownError{ Message = e.Message });
});
}
} The public method here is registered by swagger on every controller since it returns an |
I was configuring NSwag for the first time and I had this error too. I think any time there's a public method that does not have an explicit decoration it assumes it's a Post. I fixed this by either explicitly adding a |
Just add Route to your Action Name, like below |
Is there any other way to get around this. I am having the same issue but my legacy code has two controller methods with the same route [Route("")] and I cannot change this. |
Hi, there is problem on generating swagger.json
Exception content in swagger.json
version used
AspNetCore v1.1.2
NSwag.AspNetCore v11.16.1
I double checked the API list and I confirm that there is no duplicated Paths, everything works but SwaggerGenerator cannot generate API documents and give the above 500 response.
One of the sample controller is defined as below:
Configuration
Also, I configured Swagger at
StartUp.cs
:ApiVersionProcessor
is referenced from #655I have tried comment out the "problematic" APIs but Swagger response with the same error to different API, eg.
The text was updated successfully, but these errors were encountered: