[BUG] Python client: response parsing fails for array of anyOf items
See original GitHub issueBug Report Checklist
- [] Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What’s the version of OpenAPI Generator used? latest master
- Have you search for related issues/PRs?
- What’s the actual output vs expected output? error during result parsing from server
- [Optional] Bounty to sponsor the fix (example)
Description
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'
openapi-generator version
latest master, 5.0.0-SNAPSHOT
OpenAPI declaration file content or url
ContainerList:
type: array
items:
anyOf:
- $ref: "#/components/schemas/FirstResultType"
- $ref: "#/components/schemas/SecondResultType"
- $ref: "#/components/schemas/ThirdResultType"
Command line used for generation
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i /local/docs/openapi.yml -g python -o /local/clients/python
Steps to reproduce
Related issues/PRs
Suggest a fix
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Parse JSON array file python error - Stack Overflow
When I use the JSON parser in python I am getting the following error: > ValueError: No JSON object could be decoded. Here...
Read more >array — Understanding JSON Schema 2020-12 documentation
There are two ways in which arrays are generally used in JSON: List validation: a sequence of arbitrary length where each item matches...
Read more >Error handling | Airbyte Documentation
The error handler can have multiple response filters. The following example is configured to ignore 404 errors, and retry 429 errors: requester:
Read more >Handling Validation Errors - python-jsonschema
When an invalid instance is encountered, a ValidationError will be raised or returned, depending on which method or function is used.
Read more >JSON validation - IBM
The JSON parser offers high-performance, standards-compliant JSON schema ... in the message fails to match any of the items in a oneOf array...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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. https://github.com/OpenAPITools/openapi-generator/pull/8325 See this working in ComposedOneOfDifferentTypes here and see tests of it here
python-experimental became the default
python
client in v6.2.0 If you upgrade your python client to that version, this feature will work for you