[BUG][Python] oneOf (with multi-level inheritance) misses code generation
Created by: tomghyselinck
Description
As a workaround for #1662 (closed) I was trying to use oneOf
, listing the first-level inheritance objects instead of the base type.
Unfortunately, this shows pops up another related issue:
The generated code wants to resolve an OneOfDog
object, but it looks like it is not generated anywhere.
Please note that you can also see that the member fields of the Pet
and Dog
parent object are missing in the AngryDog
(cfr. #453 (closed)).
openapi-generator version
I used OpenAPI generator CLI version 4.0.0-SNAPSHOT
:
https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/openapi-generator-cli-4.0.0-20181210.103357-85.jar
OpenAPI declaration file content or url
See oneOf-multi-level-inheritance.yaml
in the attached zip-file:
oneOf-multi-level-inheritance.zip
Command line used for generation
java -jar openapi-generator-cli-4.x.jar generate -i ./oneOf-multi-level-inheritance.yaml -g python -o ./oneOf-multi-level-inheritance/client/python
Steps to reproduce
-
Generate client code
See also
oneOf-multi-level-inheritance.sh
.wget \ 'https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/openapi-generator-cli-4.0.0-20181210.103357-85.jar' \ -O 'openapi-generator-cli-4.x.jar' rm -rf ./oneOf-multi-level-inheritance/ java -jar openapi-generator-cli-4.x.jar generate -i ./oneOf-multi-level-inheritance.yaml -g python -o ./oneOf-multi-level-inheritance/client/python
-
Start (mocked) server
python3 -m connexion run --mock=all oneOf-multi-level-inheritance.yaml
-
Run the client test
(cd multi-level-inheritance/client/python/ && python3)
import openapi_client api = openapi_client.DefaultApi() dog = api.dog_get() print(type(dog)) print(dog) pet = api.pet_get() print(type(pet)) print(pet)
Output:
<class 'openapi_client.models.angry_dog.AngryDog'> {'byting': True} Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/tom/programming/XRA-31/components/software/1.x-sc_qam/xra31api-rest/issues/oneOf-multi-level-inheritance/client/python/openapi_client/api/default_api.py", line 138, in pet_get (data) = self.pet_get_with_http_info(**kwargs) # noqa: E501 File "/home/tom/programming/XRA-31/components/software/1.x-sc_qam/xra31api-rest/issues/oneOf-multi-level-inheritance/client/python/openapi_client/api/default_api.py", line 205, in pet_get_with_http_info collection_formats=collection_formats) File "/home/tom/programming/XRA-31/components/software/1.x-sc_qam/xra31api-rest/issues/oneOf-multi-level-inheritance/client/python/openapi_client/api_client.py", line 335, in call_api _preload_content, _request_timeout) File "/home/tom/programming/XRA-31/components/software/1.x-sc_qam/xra31api-rest/issues/oneOf-multi-level-inheritance/client/python/openapi_client/api_client.py", line 174, in __call_api return_data = self.deserialize(response_data, response_type) File "/home/tom/programming/XRA-31/components/software/1.x-sc_qam/xra31api-rest/issues/oneOf-multi-level-inheritance/client/python/openapi_client/api_client.py", line 246, in deserialize return self.__deserialize(data, response_type) File "/home/tom/programming/XRA-31/components/software/1.x-sc_qam/xra31api-rest/issues/oneOf-multi-level-inheritance/client/python/openapi_client/api_client.py", line 274, in __deserialize klass = getattr(openapi_client.models, klass) AttributeError: module 'openapi_client.models' has no attribute 'OneOfDog'
Related issues/PRs
Suggest a fix
I have no clue here (yet)