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
The Python client expects a property of type object
to be a dict, which seems to be compliant with the JSON schema specification.
object: An unordered set of properties mapping a string to an instance, from the JSON "object" value
However, this causes problems in combination with e.g. a Java server, where everything can be an object.
For example, the API might allow an attribute to be either a string, a boolean, or a number, which can't be handled by the Python client.
The provided example generates an error value is not a valid dict (type=type_error.dict)
. Even if the object is explicitly annotated with anyOf
and the corresponding data types, the error is the same.
openapi-generator version
7.0.0-beta
OpenAPI declaration file content or url
or with anyOf
...
properties:
name:
type: object
description: "A string, a number or a boolean"
anyOf:
- type: string
- type: integer
format: int64
- type: number
format: double
- type: boolean
...
Generation Details
java -jar .\openapi-generator-cli-7.0.0-beta.jar generate -i .\openapi.yaml -g python -o .\python\
Steps to reproduce
- Create a virtual environment
python -m venv venv
- Install the newly generated api client
pip install .\python\
- Run the following code:
from openapi_client.api.default_api import DefaultApi
from openapi_client.models.pet import Pet
api = DefaultApi()
if __name__=="__main__":
pet = Pet(id=123, name="Test")
api.add_pet(pet)
- The following error occurs:
pydantic.error_wrappers.ValidationError: 1 validation error for Pet
name
value is not a valid dict (type=type_error.dict)
Related issues/PRs
Suggest a fix
It seems to me that the client is generated according to the JSON schema specification, however this is useless in the scenario shown above. The old python client python-prior
allowed an object to be anything. Personally, I think this should be the desired behavior with the new client as well.