i runned swagger on localhost and everything was great, but after i deployed it cannot adapt the change in url and redirecting everything to the host, here is my code:
app.UseSwaggerUi3(settings =>
{
settings.DocumentPath = "/api/specification.json";
if(!app.Environment.IsDevelopment())
settings.SwaggerRoutes.Add(new SwaggerUi3Route(pathBase,
$"/some-service/api/specification.json"));
});
services.AddEndpointsApiExplorer();
services.AddOpenApiDocument((configure, sp) =>
{
configure.Title = "SMSService API";
// Add the fluent validations schema processor
var fluentValidationSchemaProcessor =
sp.CreateScope().ServiceProvider.GetRequiredService<FluentValidationSchemaProcessor>();
configure.SchemaProcessors.Add(fluentValidationSchemaProcessor);
configure.OperationProcessors.Add(new AspNetCoreOperationSecurityScopeProcessor("JWT"));
});
After some research i added this
app.UseOpenApi(options =>
{
options.PostProcess = (document, request) =>
{
var serverUrl = $"http://{request.Host.Value}/some-service";
document.Servers.Clear();
document.Servers.Add(new OpenApiServer { Url = serverUrl });
};
});
After i deployed it's ignoring the some-service
part in url, how can i fix it?