Closed
Description
DESCRIPTION
In a simple project that uses JsonApiDotNetCore.OpenApi.Swashbuckle, when I create a single resource and do something like:
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// BEGIN FOOTGUN
builder.Services.AddOpenApiForJsonApi();
builder.Services.AddJsonApi(opts => {
opts.Namespace = "api";
}, discovery: discovery => discovery.AddCurrentAssembly());
// END FOOTGUN
// ...
var app = builder.Build();
app.UseJsonApi();
I repeatedly get the error described in #1179:
JsonApiDotNetCore.Errors.InvalidConfigurationException: Multiple controllers found for resource type 'myResources': 'MyApp.Api.Library.MyResource.MyResourceController' and 'MyApp.Api.Library.MyResource.MyResourceController'
- This happens whether I use the
[Resource]
attribute or define an explicit controller. - It happens whether I use automatic discovery or manually register the resource.
Any of the following changes stops the error from occurring:
- Removing the call to
app.UseJsonApi();
- Removing
JsonApiDotNetCore.OpenApi.Swashbuckle
from the project - Putting the
AddOpenApiForJsonApi()
call afterAddJsonApi()
STEPS TO REPRODUCE
- Use both JsonApiDotNetCore and JsonApiDotNetCore.OpenApi.Swashbuckle in a project.
- Call
Services.AddOpenApiForJsonApi()
beforeServices.AddJsonApi()
. - Start the project.
EXPECTED BEHAVIOR
I would expect the package to handle this gracefully or surface an error telling me that I need to call those methods in a specific order.
ACTUAL BEHAVIOR
I see an error for which the only matching issue in Github tells me it's a problem with source generation in .NET 6.
VERSIONS USED
- JsonApiDotNetCore version: 5.7.1
- .NET Core version: 8.0.410
- Entity Framework Core version: N/A
- Database provider: N/A