swagger-api / swagger-api/swagger-codegen
[python] valid swagger input results in unusable python client
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I'm attempting to use swagger-codegen to create a python client for the the following swagger input: swagger.json.txt. The resulting client is unable to be imported into a python repl:
In [2]: from swagger_client.api_client import ApiClient
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-f419a6e2dcad> in <module>()
----> 1 from swagger_client.api_client import ApiClient
~/Code/python_cloud_client/client/swagger_client/__init__.py in <module>()
17
18 # import apis into sdk package
---> 19 from swagger_client.api.authentication_api import AuthenticationApi
20 from swagger_client.api.clusters_elasticsearch_api import ClustersElasticsearchApi
21 from swagger_client.api.clusters_kibana_api import ClustersKibanaApi
~/Code/python_cloud_client/client/swagger_client/api/__init__.py in <module>()
4
5 # import apis into api package
----> 6 from swagger_client.api.authentication_api import AuthenticationApi
7 from swagger_client.api.clusters_elasticsearch_api import ClustersElasticsearchApi
8 from swagger_client.api.clusters_kibana_api import ClustersKibanaApi
~/Code/python_cloud_client/client/swagger_client/api/authentication_api.py in <module>()
19 import six
20
---> 21 from swagger_client.api_client import ApiClient
22
23
~/Code/python_cloud_client/client/swagger_client/api_client.py in <module>()
25
26 from swagger_client.configuration import Configuration
---> 27 import swagger_client.models
28 from swagger_client import rest
29
~/Code/python_cloud_client/client/swagger_client/models/__init__.py in <module>()
27 from swagger_client.models.basic_failed_reply import BasicFailedReply
28 from swagger_client.models.basic_failed_reply_element import BasicFailedReplyElement
---> 29 from swagger_client.models.bool_query import BoolQuery
30 from swagger_client.models.capacity_constraints_resource import CapacityConstraintsResource
31 from swagger_client.models.change_source_info import ChangeSourceInfo
~/Code/python_cloud_client/client/swagger_client/models/bool_query.py in <module>()
17 import six
18
---> 19 from swagger_client.models.query_container import QueryContainer # noqa: F401,E501
20
21
~/Code/python_cloud_client/client/swagger_client/models/query_container.py in <module>()
17 import six
18
---> 19 from swagger_client.models.bool_query import BoolQuery # noqa: F401,E501
20 from swagger_client.models.exists_query import ExistsQuery # noqa: F401,E501
21 from swagger_client.models.match_query import MatchQuery # noqa: F401,E501
ImportError: cannot import name 'BoolQuery'
Swagger-codegen version
I've attempted to use the stable 2.3.1, as well as 2.4.0-20181023.093755-340, with the same issue.
Swagger declaration file content or url
Also linked above: swagger.json.txt
Command line used for generation
java -jar swagger-codegen-client.jar generate \
-i swagger.json \
-l python \
-o python-ece-client
Steps to reproduce
- Generate the client using the command above
- Go into python REPL
- Attempt to import the API client
from swagger_client.api_client import ApiClient
Related issues/PRs
I wasn't able to locate anything
Suggest a fix/enhancement
From what I can tell from the generated code, it appears that there might be some circular references that throw it off - for example in this case, BoolQuery has a QueryContainer which has a BoolQuery.
Let me know if I can provide anything else that might be helpful!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked swagger.json.txt and reproduce the command using the Python generator. Inspect the generated swagger_client/models/bool_query.py and query_container.py files, then verify that from swagger_client.api_client import ApiClient imports successfully without the circular-reference failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100