Closed sjmorgan81 closed 4 years ago
Since your API definition does not specify servers
, the base path for requests defaults to /
. To change the base path to http://example.net/foo
, add the following servers
section to your API definition:
"servers": [
{"url": "http://example.net/foo"} // or just "/foo"
]
I am having this issue in .NET 6 project. I am sorry but where do we add this setting?
Since your API definition does not specify
servers
, the base path for requests defaults to/
. To change the base path tohttp://example.net/foo
, add the followingservers
section to your API definition:"servers": [ {"url": "http://example.net/foo"} // or just "/foo" ]
I am having this issue in .NET 6 project. I am sorry but where do we add this setting?
@velmohan In my case it's an ASP.NET project and I add it via the Configure
method of my Startup.cs:
app.UseSwagger(options => options.PreSerializeFilters.Add((swagger, httpReq) =>
{
if (httpReq.Host.Host == "example.net")
{
swagger.Servers = new List<OpenApiServer> { new OpenApiServer { Url = "/foo", Description = "Blah blah blah" } };
}
}));
Thank you @sjmorgan81. That worked for me.
Sorry but this is not a real solution, because the path should be deduced by original request sent by behind reverse proxies. An example on nginx ingress controller (k8s), you can have two endpoints for the same application, and only one of them could work.
In this case, how can be able to resolve swagger ?
Q&A (please complete the following information)
Content & configuration
Example Swagger/OpenAPI definition:
Swagger-UI configuration options:
Describe the bug you're encountering
The root of my deployed API is
http://example.net/foo/
. However, when I use "Try it out", instead of a the request getting sent to a URL such ashttp://example.net/foo/Address/LpiKey?lpiKey=123
it gets sent tohttp://example.net/Address/LpiKey?lpiKey=123
(i.e. the "foo" directory where the app is hosted and where I navigate to get the Swagger UI is missing).This only happens the app is running under IIS. It works fine when it's running on my local machine using Kestrel.
To reproduce...
http://example.net/foo/
Expected behavior
A request is sent to one of the
http://example.net/foo/...
endpoints.