OpenAPITools / OpenAPITools/openapi-generator
[BUG] when using openapi-generator for pythno with a dictionary of list, the generated api_client fails
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using openapi-generator with the json https://github.com/NASA-PDS/pds-api-client/blob/main/swagger.json
and command line
openapi-generator generate -g python -i swagger.json --package-name pds.api_client --additional-properties=packageVersion=0.2.0
the package fails with error:
Traceback (most recent call last):
File "client-demo.py", line 16, in
api_response = collections.get_collection(start=0, limit=20)
File "/Users/loubrieu/PycharmProjects/pds-api-client/pds/api_client/api/collections_api.py", line 179, in get_collection
return self.get_collection_with_http_info(**kwargs) # noqa: E501
File "/Users/loubrieu/PycharmProjects/pds-api-client/pds/api_client/api/collections_api.py", line 285, in get_collection_with_http_info
collection_formats=collection_formats)
File "/Users/loubrieu/PycharmProjects/pds-api-client/pds/api_client/api_client.py", line 370, in call_api
_preload_content, _request_timeout, _host)
File "/Users/loubrieu/PycharmProjects/pds-api-client/pds/api_client/api_client.py", line 209, in __call_api
return_data = self.deserialize(response_data, response_type)
File "/Users/loubrieu/PycharmProjects/pds-api-client/pds/api_client/api_client.py", line 281, in deserialize
return self.__deserialize(data, response_type)
File "/Users/loubrieu/PycharmProjects/pds-api-client/pds/api_client/api_client.py", line 320, in __deserialize
return self.__deserialize_model(data, klass)
File "/Users/loubrieu/PycharmProjects/pds-api-client/pds/api_client/api_client.py", line 659, in __deserialize_model
kwargs[attr] = self.__deserialize(value, attr_type)
File "/Users/loubrieu/PycharmProjects/pds-api-client/pds/api_client/api_client.py", line 298, in __deserialize
for sub_data in data]
File "/Users/loubrieu/PycharmProjects/pds-api-client/pds/api_client/api_client.py", line 298, in
for sub_data in data]
File "/Users/loubrieu/PycharmProjects/pds-api-client/pds/api_client/api_client.py", line 320, in __deserialize
return self.__deserialize_model(data, klass)
File "/Users/loubrieu/PycharmProjects/pds-api-client/pds/api_client/api_client.py", line 659, in __deserialize_model
kwargs[attr] = self.__deserialize(value, attr_type)
File "/Users/loubrieu/PycharmProjects/pds-api-client/pds/api_client/api_client.py", line 303, in __deserialize
for k, v in six.iteritems(data)}
File "/Users/loubrieu/PycharmProjects/pds-api-client/pds/api_client/api_client.py", line 303, in
for k, v in six.iteritems(data)}
File "/Users/loubrieu/PycharmProjects/pds-api-client/pds/api_client/api_client.py", line 309, in __deserialize
klass = getattr(pds.api_client.models, klass)
AttributeError: module 'pds.api_client.models' has no attribute 'list'
When running for example
python client-demo.py
(find the file https://github.com/NASA-PDS/pds-api-client/blob/main/client-demo.py).
I was expecting the command to run without failre and return the response of the API server.
openapi-generator version
% openapi-generator --version
openapi-generator-cli 4.3.1
commit : 003165c
built : 2020-05-06T09:38:39Z
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/
OpenAPI declaration file content or url
https://github.com/NASA-PDS/pds-api-client/blob/main/swagger.json
Generation Details
openapi-generator generate -g python -i swagger.json --package-name pds.api_client --additional-properties=packageVersion=0.2.0
Steps to reproduce
Related issues/PRs
Suggest a fix
Here is a pull request
https://github.com/OpenAPITools/openapi-generator/pull/10004
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 by running the listed openapi-generator command with swagger.json, then inspect the generated pds/api_client/api_client.py and collections_api.py while reproducing the failure with client-demo.py. Done means the generated client handles the dictionary-of-list response without the AttributeError and client-demo.py returns the API response; a pull request for this issue is already linked in the report.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100