-
-
Notifications
You must be signed in to change notification settings - Fork 773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Servers are not showing up in openapi 3.0.1 #1139
Comments
Hey @caffeinatedMike - In order to support path-altering reverse proxies (and multiple servers with various paths), there is code that uses You can find the relevant code here: Connexion also uses the spec to define the base path for the API, so if we have multiple servers in the servers list (with different paths), it's not clear which one the connexion instance should be. At the moment it assumes the first server in the list, but can answer to multiple hosts or prefixes if headers are set by a reverse proxy. I'd love to support your use-case also, unfortunately I haven't figured out a good way to do so without breaking reverse-proxy support. Please let me know if you have any ideas. While the OpenAPI spec is very clear about the |
You should be able to override the behavior like this class MyInternalHandlers(InternalHandlers):
def _spec_for_prefix(self):
return self.specification.raw
class MyFlaskApi(FlaskApi):
@property
def _handlers(self):
# type: () -> InternalHandlers
if not hasattr(self, '_internal_handlers'):
self._internal_handlers = MyInternalHandlers(self.base_path, self.options, self.specification)
return self._internal_handlers |
@dtkav thanks for the quick and verbose response. It was actually much more complicated of a response than I had expected to be honest (not a bad thing!). I think I might be able to hopefully offer some help in accomplishing this by pointing you towards the flasgger Flask plugin that I've used to accomplish this in past. At least I didn't seem to have any problem with the multiple servers. The only test I can remember doing was testing the QA server baseurl from my local (127.0.0.0) instance and it worked. Let me know if this helps at all. |
@dtkav I was thinking, I'm not sure using |
hey @caffeinatedMike -
Unfortunately we can't treat them as absolute paths, because any of these servers could be hosted behind a path-altering reverse proxy (with a basepath like For each of these servers, we need to serve up a templated swagger-ui that is correctly configured to hit the API. Hopefully this sheds some light on why it's necessary to inspect the requests as they come in, and to use |
@dtkav that does make sense. However, I think adding some additional logic to only utilize |
Why would these not be considered valid urls in the servers block: - .
- ../
- ../api See my comment here. The OpenAPI spec allows relative paths. They are meant to be relative to where the openapi.json file is served. Handling relative paths properly solves all of these issues (at least in my mind). |
Is this a hard requirement? In my experience, I use a relative url as supported by the spec so I can run requests against the current host and then have an enumeration that can split my hosts by environment or something of that nature (which also doesn't work with the Example: servers:
- url: /v1
- url: https://load-balanced-name{env}.domain.com/v1
variables:
env:
default: ''
enum:
- ''
- .staging
- .development Maybe have enforcement by the package to enforce basePath to be equal across all url variants if that's required? |
We are using https://github.com/nginx-proxy/nginx-proxy to serve our OpenAPI 3.0.1 YAML with Connexion But Connexion override the server path and server a When using connexion I usually expect the behavior I defined in the Would it make sense for Connexion to not override the |
Description
I've defined three servers with urls and descriptions to have easy access during all phases of development. However, the servers are not showing up when viewing the swagger ui served by connexion. If I use the same yaml below on https://editor.swagger.io/ the Servers dropdown is correctly populated.
Expected behaviour
The servers should show up in the Servers dropdown.
Actual behaviour
The Servers dropdown is empty.
Steps to reproduce
/entities
folder withbrand.py
and__init__.py
brand.py
init.py
/static/swagger.yaml
Additional info:
Output of the commands:
python --version
=>Python 3.7.6
pip show connexion | grep "^Version\:"
=>Version: 2.5.1
The text was updated successfully, but these errors were encountered: