-
Notifications
You must be signed in to change notification settings - Fork 38
Closed
Labels
ServerImprovements or additions to the server codeImprovements or additions to the server code
Description
Describe the bug
When loading /swagger or /swagger/v1/swagger.json set up with Swashbuckle, I receive the following error:
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Error: An unhandled exception has occurred while executing the request.
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Conflicting method/path combination "DELETE {id}" for actions - Sample.TodoApi.Controllers.ItemsController.DeleteAsync (Sample.TodoApi),Sample.TodoApi.Controllers.ListsController.DeleteAsync (Sample.TodoApi). Actions require a unique method/path combination for Swagger/OpenAPI 3.0. Use ConflictingActionsResolver as a workaround
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.PrepareGenerateOperation(IGrouping`2 group)
at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperationsAsync(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePathsAsync(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository, Func`3 operationsGenerator)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePathsAsync(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwaggerAsync(String documentName, String host, String basePath)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Error: An unhandled exception has occurred while executing the request.
Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches:
Sample.TodoApi.Controllers.ItemsController.ReadAsync (Sample.TodoApi)
Sample.TodoApi.Controllers.ListsController.ReadAsync (Sample.TodoApi)
at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ReportAmbiguity(Span`1 candidateState)
at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ProcessFinalCandidates(HttpContext httpContext, Span`1 candidateState)
at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.Select(HttpContext httpContext, Span`1 candidateState)
at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.MatchAsync(HttpContext httpContext)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
To Reproduce
- Create an AppDbContext with two datasets.
- Create two controllers, each of which have an attribute
[Route("tables/[controller]")]on them. See https://communitytoolkit.github.io/Datasync/in-depth/server/index.html#create-a-table-controller - Program.cs looks like this:
using CommunityToolkit.Datasync.Server;
using CommunityToolkit.Datasync.Server.Swashbuckle;
using Microsoft.EntityFrameworkCore;
using Sample.TodoApi.Database;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<AppDbContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetConnectionString("Database"), sqlOptions =>
{
sqlOptions.EnableRetryOnFailure();
});
if (builder.Environment.IsDevelopment())
{
options.EnableDetailedErrors();
options.EnableSensitiveDataLogging();
options.EnableThreadSafetyChecks();
}
});
builder.Services.AddHttpContextAccessor();
builder.Services.AddDatasyncServices();
builder.Services.AddControllers();
builder.Services
.AddEndpointsApiExplorer()
.AddSwaggerGen(options => options.AddDatasyncControllers())
.AddSwaggerGenNewtonsoftSupport();
var app = builder.Build();
await using (var scope = app.Services.CreateAsyncScope())
{
var context = scope.ServiceProvider.GetRequiredService<AppDbContext>();
await context.InitializeAsync(app.Environment);
}
app.UseHttpsRedirection();
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
options.RoutePrefix = string.Empty;
});
app.UseAuthorization();
app.MapControllers();
app.Run();Expected behavior
No error - OpenAPI.yaml / swagger.json is created.
What platforms?
- Server:
- Version of dotnet being used to compile? dotnet 8.0.420
- Library versions? 8.0.2, EF Core 8.0.8, ASP.NET Core 8.0.8
- What database are you using? SQL LocalDB
- Where are you running the server? Localhost
Metadata
Metadata
Assignees
Labels
ServerImprovements or additions to the server codeImprovements or additions to the server code