You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Python client: response parsing fails for array of anyOf items #6546
If openapi definition contains model of type array with anyOf items description, generated Python client can't parse request from server. Generated model has openapi_types with next type list[AnyOfFirstSecondThird]. During response parsing client takes one by one list items and try to de-serialize to non existing type klass AnyOfFirstSecondThird. Parsing fails at klass = getattr(openapi_client.models, klass) line with next error - module 'openapi_client.models' has no attribute 'AnyOfFirstSecondThird'
@hleb-albau have you tried using the python-experimental generator?
The python generator does not fully implement composed schemas but the python-experimentalgenerator does.
You can see tests of the anyOf class gmFruit here
That class is defined here
and is defined as:
@spacether
I tried to use python-experimental and got same results, but with slight different error - KeyError sys.modules[model.any_of_first_second_third']. And of course, model package does not contain any_of_first_second_third.
Also, the problem not directly related to case tested by gmFruit , but rather combination of array and it's type definition.
Btw, I tried online swagger editor and generate another version on client. Seems it is generated by swagger-generator. Using that client I get lucky with response parsing. But in the middle of de-serialization anyOf types were lost and replaces by raw dict.
I should prepare some full example, need some time.
In the short term, you could make an anyOf model which contains your anyOf definition. Then in your array model, just $ref to your new anyof model. That should work in python-experimental.
We also had a PR that just landed which creates arrayModels in python-experimental so
you will no longer get the import error
but your example may or may not work, not sure if our array model PR fixes your use case
This issue's root cause is that inline composed schemas are not handled by generators at this time.
Our tooling assumes that composed schemas are defined in components.
A more general solution is to add composed schema CodegenProperties and have generators use that inline definition.
These issues have the same root cause:
In this proof of concept PR I show how we can add composed schema info to:
CodegenModel/CodegenProperty/CodegenParameter/CodegenResponse and then we can define these composed schemas at any level in generated code. #8325
See this working in ComposedOneOfDifferentTypes here and see tests of it here
Activity
auto-labeler commentedon Jun 4, 2020
👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
spacether commentedon Jun 4, 2020
@hleb-albau have you tried using the
python-experimentalgenerator?The
pythongenerator does not fully implement composed schemas but thepython-experimentalgenerator does.You can see tests of the anyOf class gmFruit here
That class is defined here
and is defined as:
hleb-albau commentedon Jun 4, 2020
@spacether
I tried to use
python-experimentaland got same results, but with slight different error -KeyError sys.modules[model.any_of_first_second_third']. And of course, model package does not contain any_of_first_second_third.Also, the problem not directly related to case tested by gmFruit , but rather combination of array and it's type definition.
Btw, I tried online swagger editor and generate another version on client. Seems it is generated by swagger-generator. Using that client I get lucky with response parsing. But in the middle of de-serialization anyOf types were lost and replaces by raw dict.
I should prepare some full example, need some time.
spacether commentedon Jun 4, 2020
Ah, I was missing that this was an array model. I though that it was an object type model. Can you provide the referenced anyOf models?
We don't yet have code coverage of this use case in python-experimental.
spacether commentedon Jun 4, 2020
In the short term, you could make an anyOf model which contains your anyOf definition. Then in your array model, just $ref to your new anyof model. That should work in python-experimental.
We also had a PR that just landed which creates arrayModels in python-experimental so
spacether commentedon Mar 26, 2021
This issue's root cause is that inline composed schemas are not handled by generators at this time.
Our tooling assumes that composed schemas are defined in components.
A more general solution is to add composed schema CodegenProperties and have generators use that inline definition.
These issues have the same root cause:
allOfand$refgenerates anobjectin the python model when it should be astring#8457In this proof of concept PR I show how we can add composed schema info to:
CodegenModel/CodegenProperty/CodegenParameter/CodegenResponse and then we can define these composed schemas at any level in generated code.
#8325
See this working in ComposedOneOfDifferentTypes here and see tests of it here
spacether commentedon Sep 16, 2022
This work in
python-experimentalOne can see anyOf endpoints here: https://github.com/OpenAPITools/openapi-generator/blob/master/samples/openapi3/client/3_0_3_unit_test/python-experimental/docs/apis/tags/AnyOfApi.md
And anof model tests here: https://github.com/OpenAPITools/openapi-generator/blob/master/samples/openapi3/client/3_0_3_unit_test/python-experimental/test/test_models/test_anyof_complex_types.py
Which are passing in CI in node 4
spacether commentedon Oct 22, 2022
python-experimental became the default
pythonclient in v6.2.0If you upgrade your python client to that version, this feature will work for you