Bug: Can't override servers url in path object
See original GitHub issueQ | 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.
- Copy the openapi yaml content here: idratherbewriting.com/learnapidoc/docs/rest_api_specifications/openapi_weather_multiple_servers.yml
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
-
Go to the Swagger online editor and paste in the yaml content.
-
Click Authorize and paste in the shown API key.
-
Expand the weatherdata endpoint (this is the last one).
-
Click Try it out.
-
In the parameters, enter the following:
- for lat, enter 37.3708698
- for lng, enter -122.037593
-
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"
Expected Behavior
The server url specified at the path level should override the global server url.
Current Behavior
The global server url is being used instead.
Context
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.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
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.
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 😄