OpenAPITools / OpenAPITools/openapi-generator
[BUG] PHP Client inconsistent unserialize behavior between object and array
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
We have created a PHP SDK using the OpenAPI Generator (openapi-generator-cli generate -i https://api.flyo.cloud/nitro/v1/openapi -g php), and we have noticed inconsistent behavior regarding the parsed results. The results for accessing data is sometimes either an object or an array. It is possible that this inconsistency is related to how the OpenAPI description is defined, although we are not entirely sure.
openapi-generator version
6.6.0
OpenAPI declaration file content or url
block:
title: Block
type: object
properties:
items:
title: BlockItems
type: array
items: {}
description: Mapping Items
example:
- title: Hello
teaser: Great!
- title: Hallo
teaser: Toll!
content:
title: BlockContent
type: object
description: Text Contents
example:
title: Hello World
I cut out the relevant part, but here is the full reference: https://api.flyo.cloud/nitro/v1/openapi
Generation Details
The screenshot below demonstrates the inconsistency, with the content section sometimes being represented as an array and sometimes as an object:
As observed in the OpenAPI file, the content section is defined with type: object. Therefore, one would expect to access its values using $block->getContent()->someVariable. However, the actual access method is $block->getContent()['someVariable']. On the other hand, in the items property, which is an array of objects, the array access method works as expected: foreach ($block->getContents() as $item) { $item->someVariable }.
Suggested Fix
To ensure consistent behavior, it is recommended to either use objects (stdClass in the PHP world) or arrays consistently throughout the SDK.
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
Begin by generating the PHP SDK from the linked OpenAPI document and tracing how the content and items properties are deserialized. Compare their resulting access patterns and clarify which consistent representation the generator should guarantee before verifying the generated client.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, php
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100