-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Python swagger-codegen hard-coded base URL #7804
Comments
I think you can change the base path in the python client during runtime. |
Yes it can be configured at runtime api_client = ApiClient()
api_client.configuration.host = "http://whatever" |
I do not like this particular approach. The reason? As an API author, I have an API where I encode a version/etc into the basepath so that the server can handle multiple versions concurrently/explicitly not handle unsupported versions. If I bump the version of the API, I expect the version in the basepath to increase as well. As a user of the client, I, for the most part, do not care about the details of the path to the API. I only care about where the API server is located. However, because the host includes both the base path and the host, I need to know the version/etc in order to construct a new host. This means that every time the API version changes, I need to update the code using the client library. The act of using the new version of the library should be sufficient, since it should be abstracting such details. For example, my client has the following line in Configuration()'s constructor:
I tried changing host to something else with the expectation that the client would just work.
However, I get 404s when I try to use the API. Looking at the server logs, I see accesses to stuff like Right now the url is constructed as follows:
I think that the host should actually be the host, and the base path something separate. I.e.
The base_path would default to Does that seem reasonable? |
https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/ The problem is that codegen is made to generate code. It is not responsible for environment... however, I strongly agree to updating the python code so it take a parameter to set the host url. As an alternative, a hosts entry can solve what this ticket is providing. |
Has any change to this behavior occurred? If not, I agree with needing to ask for hostname and port as a required argument when initializing the API client. I've recently begun modeling APIs with OAS3 for products that are explicitly and exclusively deployed on-premise. This means there is no SaaS to point to for a baseUrl, and that hardcoding one is not useful as it will always result in error. Therefore, the API client should require a host/port (socket) to be passed to the API client at runtime. I see where this can be modified in the Configuration class (for example, in the generated python library); however, I would much prefer to do it programmatically in the generator. |
Description
Swagger API client for python should allow for the base URL to be passed via arguments at runtime
Swagger-codegen version
2.3.1
Swagger declaration file content or url
Any, can use petstore.
Command line used for generation
swagger-codegen generate -i swagger.yaml -l python -o client-lib
Steps to reproduce
Cannot pass URL to client library
Related issues/PRs
Suggest a fix/enhancement
Instead of hard-coding the base URL like here, instead pass it as a parameter to init in Configuration (or anywhere else that makes sense).
The text was updated successfully, but these errors were encountered: