| Q | A
| ------------------------------- | -------
| Bug or feature request? | Bug
| Which Swagger/OpenAPI version? | 3.0
| Which Swagger-UI version? | 3.4.0
| How did you install Swagger-UI? | Used the standalone dist bundle
| Which browser & version? | Chrome, latest
| Which operating system? | MacOS X
On this Swagger doc page about API Server and Basepath, the section on "Overriding Servers" says that I can specify different server URLs for different paths. However, when I execute an operation in Swagger UI (or in the online Swagger editor, the submitted curl request does not use the specified server url for that path. Instead, the curl request uses the global server url.
(Ron said to file this issue as a bug.)
Here are steps to reproduce this issue.
Note that in the /weatherdata path, I have a different server URL declared:
/weatherdata:
get:
tags:
- Full Weather Data
servers:
- url: https://another.simple-weather.p.mashape.com
In the parameters, enter the following:
Click Execute.
The curl submitted shows this:
curl -X GET "https://simple-weather.p.mashape.com/weatherdata?lat=37.3708698&lng=-122.037593" -H "accept: application/json" -H "X-Mashape-Key: EF3g83pKnzmshgoksF83V6JB6QyTp1cGrrdjsnczTkkYgYrp8p"
It should show the other server url instead:
curl -X GET "https://another.simple-weather.p.mashape.com/weatherdata?lat=37.3708698&lng=-122.037593" -H "accept: application/json" -H "X-Mashape-Key: EF3g83pKnzmshgoksF83V6JB6QyTp1cGrrdjsnczTkkYgYrp8p"
The server url specified at the path level should override the global server url.
The global server url is being used instead.
The API I'm describing has different URLs for different endpoints. (The sample YAML here is not the actual API I'm working with -- I just used it to demonstrate the issue.) Right now, if you try to execute one endpoint, it submits the wrong curl and errors out. You have to manually select a different server URL in the global servers dropdown, which is unintuitive given that our server urls don't logically map to path names.
I can also confirm this issue. The documentation here reports this as a feature available:
https://swagger.io/docs/specification/api-host-and-base-path/
However, currently it does not work that way.
I didn't find a way to define servers globally in swagger-jaxrs2 (2.0.0-rc2).
So I can define it on a level of operation:
@Operation(servers = {@Server(url = "https://myserver.com/mypath/")},
but it is not supported by the SWAGGER-UI.
On the other hand there is no @Servers tag to put on the global level.
That's life.
@redmitry that's an issue to be opened on swagger-core.
Same issue here... Overwriting server on path level does not seem to work
Implemented! See #3972 for a screenshot of this in action.
This will go live in tomorrow's release. Thanks to @tomjoht and everyone else for pitching in here :smile:
Most helpful comment
I can also confirm this issue. The documentation here reports this as a feature available:
https://swagger.io/docs/specification/api-host-and-base-path/
However, currently it does not work that way.