-
Notifications
You must be signed in to change notification settings - Fork 118
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
How to change host in the swagger file? #235
Comments
@analogue I don't recollect a way of providing the host during request call if schema file is read via |
There doesn't look to be a publicly documented non-invasive way to do this. A PR to address this would be awesome. In the meantime, you might be able to get away with something like this: from bravado_core.spec import build_api_serving_url
client = SwaggerClient.from_url(...)
# suggested
client.swagger_spec.api_url = build_api_serving_url(...)
# or even
client.swagger_spec.api_url = <whatever you want it to be> |
Thank you so much for the suggestions! |
This is a very basic requirement for using microservices. I don't know what the host and port will be, but I get them dynamically and load them into Bravado, which then creates a client that bravely attempt to connect to the statically defined host/port endpoint as denoted in the swagger.json file... |
@advance512 if you load a spec from a file, this will do the trick (this is how we do it internally): from bravado.client import SwaggerClient
from bravado.swagger_model import load_file
spec_dict = load_file(spec_path)
spec_dict['host'] = '{}:{}'.format(host, port) |
But I'm not loading it from a file. I have an endpoint from which I construct a URL: http://host:port/service/swagger.json I give this URL to Bravado. It creates a client that instead of using: uses: http://staticHost:staticPort/service/ I can create an HTTP client and download the file, and use load_file instead - it seems overkill. I'd much rather do:
I follow @analogue's example instead. |
@advance512 your issue is similar but different from the one the original poster discussed. You can just remove the Ideally the host that you use in the URL should be a load balancer (or something similar) that will then route the request to one of your microservice instances. At Yelp we use SmartStack for this purpose. |
iirc, not putting a host/port caused bravado to complain and die.. but I'll check it out, just to be sure. |
I just started using the library (thanks). A question on API usage:
My yml file looks like this:
I can successfully load the swagger file and create a client:
My question is how do I at runtime replace the localhost in the swagger file with the address of the server (e.g. 129.100:90.6:9000) using bravado api? My swagger file is stored locally and not a server.
For know I am replacing the text in the swagger file before calling load_file. I tried to use RequestsClient.separate_params to set the 'url', but no success. I have also tried setting via origin_url or config, using the from_spec method (no success):
Thanks for your help, Shahriar
The text was updated successfully, but these errors were encountered: