My Web API has four controllers: Login, Users, Products and Sales. There are also three different client applications and each of these just use a single controller. Administrators have an User Administration app, Managers have a Product management App and customers have a "Buy this" app. So, three different Web API's?
Well, no. As all controllers share the same database so we want it all contained in a single project. They also share some functionality in the background and all APIs also need to support the Login controller.
What I want is that my API has three different URLs:
These should be three different Swagger endpoints, each with the Login controller. I just wonder if this is even possible or if I need three different projects to get this to work.
Well, I had to find this post about multiple Swagger documents but I managed to get it to work.
It starts with the builder.Services.AddSwaggerGen() where you use options.SwaggerDoc() multiple times to create multiple documents.
Then, using app.UseSwaggerUI() you add multiple endpoints for each doc. specifying the related document names from the previous step.
And with each controller you add [ApiExplorerSettings(GroupName = "...")]
to link the controller to a specific document. Without it, they end up in all documents...
The result is that I now have a single project that holds multiple Swagger endpoints and thus multiple Web API's.