We're trying to add SwaggerUI Docs to IdentittyServer4 (.NET Core 6) to include Custom Endpoints (localapi). The Swagger UI is generated but the Components json object is empty. The API Controllers are decorated with [ApiController] and either [AllowAnonymous] or [Authorize(LocalApi.PolicyName)].
The Swagger UI returns the following.
"No operations defined in spec!"
{
"openapi": "3.0.1",
"info": {
"title": "Bev360.IDP",
"version": "1.0"
},
"paths": { },
"components": { }
}
Our Identity Server project Program.cs file includes the following
builder.Services.AddLocalApiAuthentication();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddRazorPages();
builder.Services.AddIdentityServer(options =>
{
//options.LicenseKey = null;
options.EmitStaticAudienceClaim = true;
options.Discovery.CustomEntries.Add("local_api", "~/api");
options.Discovery.CustomEntries.Add("swagger_docs", "~/swagger/index.html");
})
.AddInMemoryIdentityResources(Config.IdentityResources)
.AddInMemoryApiScopes(Config.ApiScopes)
.AddInMemoryApiResources(Config.ApiResourcea)
.AddInMemoryClients(Config.Clients)
.AddAspNetIdentity<ApplicationUser>();
app.UseAuthentication();
app.UseSwagger();
app.UseSwaggerUI();
app.UseStaticFiles();
app.UseHttpsRedirection();
app.UseRouting();
app.UseIdentityServer();
app.UseAuthorization();
app.MapRazorPages().RequireAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
I forgot to add
builder.Services.AddControllers();