NSwag
NSwag copied to clipboard
Generating multiple OpenAPI documents and UIs describing different pieces of the API
I have a set of APIs that's available under /api/v1/
route, and a set of internal APIs (stuff that makes the admin panel tick and such) under /admin/api/v1/
route. I currently have NSwag with OpenAPI documents and SwaggerUI3 implemented, but it contains all routes.
After a couple of hours of googling, cursing, and I'm pretty sure getting a mild aneurysm, I managed to scavenge what precious few bits and pieces of information exist and cobble together this bit of code:
// OpenAPI
app.UseOpenApi();
app.UseSwaggerUi3(settings =>
{
settings.Path = "/swagger";
});
// OpenAPI Internal
app.UseOpenApi(settings =>
{
settings.Path = settings.Path.Replace("swagger", "swagger-internal");
});
app.UseSwaggerUi3(settings =>
{
settings.Path = "/swagger-internal";
settings.DocumentPath = settings.DocumentPath.Replace("swagger", "swagger-internal");
});
which does provide me with two separate documents, and two separate UIs. However, despite their differing routes, they share the functionality, fully.
I found this issue that barely has enough information to direct me to a deleted file from the repo and this documentation that's of minuscule if any help at all.
I know that I can write some filter or something (how, though, that's anybody's guess) and use this bit of code:
services.AddOpenApiDocument(settings =>
{
// the settings here in particular
});
and perhaps, yet again, duplicate it or something. But this is where I'm absolutely and utterly stuck and I have no idea how to progress further. I only know that all those bits and pieces of code are glued together with magic strings, but where to apply the glue in this case, that I do not know.
I heard rumors and legends that someone somewhen knew a distant relative of somebody who managed to do that, so perhaps I'll be lucky and this person is here.