OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Python Client] Python client is unable to resolve complex structure under AnyOf

Open
#19,015 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

Attempting to post data using python client results in a error when the data structure for the data in OpenAPI spec contains combination of complex structure and anyof data type.

openapi-generator version

7.6.0

OpenAPI declaration file content or url

https://gist.github.com/OptimeeringBigya/7130bdeb5ed6cdc474ee2d3c5897c1b4

Generation Details

java -jar openapi-generator-cli.jar generate
--input-spec ./test_openapi_json.json
--generator-name python
--output ./test_python_client

Steps to reproduce
  1. Install venv
  2. Using the venv, execute in python:
from test_python_client.openapi_client.api.default_api import DefaultApi
from test_python_client.openapi_client.models.data import Data

data = [
    {
        "prediction_for": "2024-06-25T09:33:46.556Z",
        "value": 0.1
    },
    {
        "prediction_for": "2024-06-25T09:33:46.556Z",
        "values": {"0.1": 0.1}
    },
    {
        "prediction_for": "2024-06-25T09:33:46.556Z",
        "values": {"N": 0.1}
    }
]
a = [Data.from_dict(i) for i in data]
print(a[0].to_dict())
print(a[1].to_dict())
print(a[2].to_dict())
response = DefaultApi().post_post(a)
print(response)
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/16110

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with test_openapi_json.json and the shown openapi-generator-cli command, then inspect the generated Data model, Data.from_dict, to_dict, and DefaultApi.post_post flow. Compare behavior with related issue #16110; done means the complex AnyOf structures in the example are resolved correctly and the generated Python client can post them without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, python
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.