OpenAPITools / OpenAPITools/openapi-generator

[BUG] PHP Client inconsistent unserialize behavior between object and array

Open
#15,803 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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:

image

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.