I have a .NET 6.0 isolated function and I have added OpenAPI support to it. This is a snippet from my Program.cs
:
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults(worker => worker.UseNewtonsoftJson())
.ConfigureServices(services =>
{
services.AddSingleton<IOpenApiConfigurationOptions>(_ =>
{
var options = new OpenApiConfigurationOptions()
{
Info = new OpenApiInfo()
{
Version = "1.0.0",
Title = "Function Name",
Description = "This is the name of the function",
Contact = new OpenApiContact()
{
Name = "Codebug"
}
},
Servers = DefaultOpenApiConfigurationOptions.GetHostNames(),
OpenApiVersion = OpenApiVersionType.V2,
IncludeRequestingHostName = true,
ForceHttps = false,
ForceHttp = false,
};
return options;
});
})
.Build();
host.Run();
This is working without any issue. When I run the function in the console, I get presented with the following urls:
FunctionName: [POST] http://localhost:7295/api/FunctionName
RenderOAuth2Redirect: [GET] http://localhost:7295/api/oauth2-redirect.html
RenderOpenApiDocument: [GET] http://localhost:7295/api/openapi/{version}.{extension}
RenderSwaggerDocument: [GET] http://localhost:7295/api/swagger.{extension}
RenderSwaggerUI: [GET] http://localhost:7295/api/swagger/ui
My function's url starts with <base url>/api/FunctionName
, however all the OpenAPI specific urls are in the root of the api route, like <base url>/api/swagger/ui
.
How can I change the OpenAPI default url so that the the urls do not appear under /api
route, but have a following format
<base url>/api/FunctionName/swagger/ui
While investigating I have come up with this Stack Overflow Answer. However it shows how to add the Swagger defaults to the app
object. I do not know how to get hold of an app
object in an isolated function where can I add the swagger default values?