OpenAPITools / OpenAPITools/openapi-generator

[BUG] [PHP] PSR-18 generator has the wrong argument to selectHeaders

Open
#17,388 2 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

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

Had this issue in a generated client and was able to find that it's present in the example client code for the PetStore API.

https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/php/psr-18/lib/HeaderSelector.php#L38

The 2nd argument to HeaderSelector is a string.

If you look at the usages on it you'll find for example, https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/php/psr-18/lib/Api/StoreApi.php#L340

showing that it tries to pass an array as the 2nd argument to selectHeaders. This fails when you try to call any API method, with:

PHP Fatal error: Uncaught TypeError: <your namespace>\HeaderSelector::selectHeaders(): Argument #2 ($contentType) must be of type string, array given

openapi-generator version

Latest master

OpenAPI declaration file content or url

As per the generated sample in the project

Generation Details
Steps to reproduce

Generate the sample PetStore client with the PSR-18 library.

Related issues/PRs
Suggest a fix

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 with samples/client/petstore/php/psr-18/lib/HeaderSelector.php and the selectHeaders call in samples/client/petstore/php/psr-18/lib/Api/StoreApi.php. Generate the PetStore client with the PSR-18 library and reproduce the PHP TypeError. Done means the generated client passes the correct argument type and API methods run without this error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.