I am running a couple of .net core webapi behind a reverse proxy. I have gotten the Swagger UI to load the swagger json. However, the operations' paths in json document are not relative,which breaks the try it out feature of the SwaggerUI as request are sent to root. How would I go about making the request relative ?
You can manipulate the Open API document using the pre-serialisation filters.
You can copy the "open API paths" to a new (temporary) collection with a new key/path, clear the original collection and copy the new collection back in to replace it:
app.UseSwagger(options =>
{
options.PreSerializeFilters.Add((openApiDocument, httpRequest) =>
{
OpenApiPaths tempOpenApiPaths = new OpenApiPaths();
foreach (KeyValuePair<string, OpenApiPathItem> openApiPath in openApiDocument.Paths)
{
tempOpenApiPaths.Add("/foo" + openApiPath.Key, openApiPath.Value);
}
openApiDocument.Paths.Clear();
foreach (KeyValuePair<string, OpenApiPathItem> openApiPath in tempOpenApiPaths)
{
openApiDocument.Paths.Add(openApiPath.Key, openApiPath.Value);
}
});
});