Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- 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
I am generating the PHP code for an external proprietary API. The OpenAPI spec contains a schema of type object
but without any properties.
The responses of the API, which contains the empty object as {}
is casted to an empty array []
in the ObjectSerializer.
Now, I need to pass a part of the deserialized object to another endpoint of the API. But when the ObjectSerializer serializes the empty array, the result is []
. As this is another data type the API refuses the request.
openapi-generator version
Version 7.11.0, but it also happens in master.
OpenAPI declaration file content or url
Here are two snippets of the OpenAPI spec:
{
"openapi": "3.0.1",
"components": {
"schemas": {
"Agreement": {
"type": "object",
"properties": {
"schufaClause": {
"$ref": "#/components/schemas/AgreementSchufaClause"
}
}
},
"AgreementSchufaClause": {
"type": "object"
}
}
}
}
Suggest a fix
I suggest to change this behaviour of the deserialization of empty objects. PHP's equivalent of an empty object is an instance of stdClass
and not an array. So it should just be returned as is - without any casting.
Although this is a edge case that should rarely happen it could potentially break existing code. What do you think about that?