OpenAPITools / OpenAPITools/openapi-generator

[BUG][PHP] ObjectSerializer.php throws ValueError when handling \SplFileObject type

Open
#10,817 1 comment 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

@wing328

Description

/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php

ObjectSerializer.php throws ValueError when handling \SplFileObject type @ line 336. This is because SplFileObject can be passed to settype(), which then throws the said error.

There is no reason to handle 'object', 'mixed', '\DateTime' in line 336, because they're handled before.

Also - there is no reason for line 336 to handle '\SplFileObject', because this specific object type is handled below.

The said object types should be deleted from the array.

openapi-generator version

5.3.0. - 6.0.0.

OpenAPI declaration file content or url

.../samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php

Line 336

Generation Details

php client

Steps to reproduce
  1. Find an endpoint that returns a PDF file.
  2. Generate PHP client that makes a GET request to the said endpoint.
  3. Use client to call the endpoint.
Related issues/PRs
Suggest a fix

replace line 336 with:
if (in_array($class, ['array', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'number', 'string', 'void'], true)) {

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

Start in samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php around line 336 and inspect how SplFileObject is handled below that condition. Reproduce the issue with a generated PHP client calling an endpoint that returns a PDF. Done means the serializer no longer throws ValueError for SplFileObject while preserving the existing handling for the other listed types.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.