Update ApiControllerBase.cs#11
Conversation
Add Attribute [ApiController] in order to generate Swagger documentation
|
I think it might be usefull also to add grouping of APIby project |
|
Hi Soruk Is having the Regarding the And yes, they are hardcoded strings meaning an integrator can not change it to his will. Any suggestions on this? |
|
Hi @thomasduft, the |
|
Hi @Soruk This is weird?! When I use and reference my latest published nuget openiddict-ui packages and setup the Swagger related stuff within the Startup/Program.cs file then I see the endpoints and I can also browse them. I usually develop within devcontainers on a linux based PC with VSCode. So to me the |
|
Hi @thomasduft Yes it is weird. |
|
Et voilà... using System.Reflection;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerUI;
using tomware.Suite.Host.Web;
using tomware.Suite.Persistence.EF;
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
var builder = WebApplication.CreateBuilder(args);
// Add services to the container => ConfigureServices
builder.Services.Configure<StorageContextOptions>(options =>
{
options.DbContextOptionsBuilder = builder =>
builder.UseSqlite(configuration.GetConnectionString("DefaultConnection"),
sql => sql.MigrationsAssembly(typeof(Program)
.GetTypeInfo()
.Assembly
.GetName()
.Name));
});
builder.Services.AddModules();
if (builder.Environment.IsDevelopment())
{
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "App", Version = "v1" });
c.DocInclusionPredicate((name, api) => true);
c.TagActionsBy(api =>
{
if (api.GroupName != null)
{
return new[] { api.GroupName };
}
var controllerActionDescriptor = api.ActionDescriptor as ControllerActionDescriptor;
if (controllerActionDescriptor != null)
{
return new[] { controllerActionDescriptor.ControllerName };
}
throw new InvalidOperationException("Unable to determine tag for endpoint.");
});
c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
});
}
// Configure
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseCors(builder =>
{
builder.WithOrigins("http://localhost:4200");
builder.AllowAnyHeader();
builder.AllowAnyMethod();
builder.AllowCredentials();
});
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "App v1");
c.DocExpansion(DocExpansion.None);
});
}
app.UseWebAppWithDefaults();
app.Run();It is part of private stuff and already on .NET 6. But you should see the swagger configuration section.... |
|
Thanks. I will check it tomorrow |
|
Ok, I have just tested your code, and still I get only the main / executing assembly api endpoints. I do not know why I cannot to get to show the api exposed by referenced assemblies. |
|
Same as well if you clone this repo and start the sample server? I can run it on a Linux based PC and a Windows based PC and always see the Swagger generated docs! |
|
I have just re-downloaded the code from main branch and I can see the other assemblies documentation. |
|
Hi @thomasduft, I think that I found the source of the problem. for versioning API, and the Controller does not have the given attribute I will check this solution from StackOverflow |
And it seems that |
|
After more investigation, when I want to filer by version the methods in the following Swagger configration: without the A little tweak, fix it: |


Add Attribute "ApiController" in order to generate Swagger documentation