swagger-api / swagger-api/swagger-codegen
[PHP] Object deserialization returns array instead of object.
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The "object" response type actually returns an array in PHP.
This can mostly be worked around, with the exception that static analyzers break because the docblock return type (object) does not match the actual return type (array).
I believe it is due to these lines:
https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache#L240-L241
} elseif ($class === 'object') {
settype($data, 'array');
The generated code has this in the docblock:
* @return object
But the resulting return type is an array.
Swagger-codegen version
2.4.2
Related issues/PRs
This is essentially a duplicate of #5553, but I wanted to add that static analyzers fail when ran against the generated code.
Suggest a fix/enhancement
Returning a stdClass seems ideal here (IMO), but altering the docblock to indicate the array return type would also fix the static analysis issue.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache at the referenced deserialization branch. Compare the generated return value with its @return object declaration and review related issue #5553 before choosing the intended behavior. Done means generated PHP code returns a value consistent with its documented type and no longer breaks static analysis.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100