Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 of 6 tasks
OptimeeringBigya opened this issue Jun 25, 2024 · 2 comments
Open
3 of 6 tasks

Comments

@OptimeeringBigya
Copy link

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

#16110

@OptimeeringBigya
Copy link
Author

Python script is failing with the following exception:

pydantic_core._pydantic_core.ValidationError: 1 validation error for post_post
1
  Input should be a valid dictionary or instance of Data [type=model_type, input_value=[Data(anyof_schema_1_vali...irectionalPrediction'})], input_type=list]
    For further information visit https://errors.pydantic.dev/2.7/v/model_type

@OptimeeringBigya
Copy link
Author

Did some digging myself.

Seems like the kwargs need to be passed into the init as actual_instance


like how it is done in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant