OData SDK v8.0.1 Creating Duplicate Routes
@corranrogue9 is already working on this.
Since Jun 3, 2025.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
When the IServiceCollection.AddOData() extension method is called, conventional and attribute routes are added. When the path template specified on an [HttpMethod] attribute is the same as the path template generated by conventional routing, two routes for the same HTTP method and path template combination are created.
Example
The example below will generate two GET odata/Items routes.
[Route("odata")]
public class ItemsController : ODataController
{
...
[HttpGet("Items")]
public IActionResult GetItems()
{
...
return Ok(items);
}
}
Reproduction Steps
> git clone git@github.com:donile/odata-duplicate-routes-example.git
> cd ./odata-duplicate-routes-example
> dotnet run --project .\src\ODataDuplicateRoutesExample\ODataDuplicateRoutesExample.csproj
HTTP GET https://localhost:5001/swagger/v1/swagger.json with your http client of choice. =)
Upon attempting to retrieve the OpenAPI schema, an HTTP response with status code 500 is returned, including the following error:
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Conflicting method/path combination "GET odata/Items" for actions - ODataDuplicateRoutesExample.Controllers.ItemsController.GetItems (ODataDuplicateRoutesExample),ODataDuplicateRoutesExample.Controllers.ItemsController.GetItems (ODataDuplicateRoutesExample). Actions require a unique method/path combination for Swagger/OpenAPI 3.0. Use ConflictingActionsResolver as a workaround
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperations(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Offer to Help
I would like to help resolve the issue and submit a PR, but before I investigate further, I was hoping I could receive some guidance regarding acceptance criteria for this feature. Is this a bug or is the observed behavior expected? If it's not the expected behavior, what is the expected behavior? The way I see it, there are three options.
- This is the expected behavior.
- When an attribute route matches the conventional route, ignore the conventional route.
- When an action method is decorated with an
[HttpMethod], ignore the conventional route.
3.1 When a controller is decorated with an[ODataAttributeRouting], do not generate conventional routes for any of the controller's action methods.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.