Skip to content
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

Setting the API Server URL bug in Docker container #9

Closed
vemonet opened this issue Sep 10, 2020 · 5 comments
Closed

Setting the API Server URL bug in Docker container #9

vemonet opened this issue Sep 10, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@vemonet
Copy link
Member

vemonet commented Sep 10, 2020

The servers url in the OpenAPI yaml definition is not changed by the provided arguments only when run in Docker containers

The exact same command:
openpredict start-api --server-url http://myurl

Works fine locally, the server URL is updated in the OpenAPI definition exposed

When run as entrypoint of a Docker... For some reason the arg is properly passed to the Python code, and the API is well started by the following line (with the right server_url):

api.add_api('openapi.yml', arguments={'server_url': server_url})

But for some reason the started API has en EMPTY servers URL (not even a / which should be the default)

Seems to be an issue with Connexion

@vemonet vemonet added the bug Something isn't working label Sep 10, 2020
@vemonet
Copy link
Member Author

vemonet commented Dec 11, 2020

Issue with Connexion default behavior. Multiple issues have been created but the default behavior is to override servers whatever the situation, and Connexion do not seems to provide ways to make sure the servers defined by the user in the openapi.yml file

spec-first/connexion#1174
spec-first/connexion#1139
spec-first/connexion#1047

The culprit: https://github.com/zalando/connexion/blob/master/connexion/apis/flask_api.py#L310

It can be solved by adding a param to disable _spec_for_prefix

An options like self.options.openapi_spec_path

self.options.disable_servers_overwrite = True

Then check it in _spec_for_prefix

@vemonet
Copy link
Member Author

vemonet commented Dec 15, 2020

Using https://pypi.org/project/flask-reverse-proxy-fix/ can help solve the issue

requirements.txt:

flask-reverse-proxy-fix
werkzeug<1

Code:

from flask_reverse_proxy_fix.middleware import ReverseProxyPrefixFix

api = connexion.App(__name__, options={"swagger_url": ""}, arguments={'server_url': server_url})

api.add_api('openapi.yml')

api.app.config['REVERSE_PROXY_PATH'] = 'http://api.collaboratory.semantiscience.org'
ReverseProxyPrefixFix(api.app)

api.run(host='0.0.0.0', port=port, debug=debug, server=deployment_server)

@micheldumontier
Copy link
Collaborator

Great! but the server url is misspelled .

@vemonet
Copy link
Member Author

vemonet commented Dec 15, 2020

Yep it works with absolute URIs and relative paths(e.g. /api or v1)

Going to try it with Smart API

@vemonet
Copy link
Member Author

vemonet commented Dec 15, 2020

Smart API still not working even with absolute URL: https://smart-api.info/ui/ff8e602615d19577fa3759240dcce951

@vemonet vemonet closed this as completed Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants