OpenAPITools / OpenAPITools/openapi-generator

[BUG][PHP] `HeaderSelector` reorders `Accept` formats

Open
#14,361 0 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

HeaderSelector reorders Accept formats.
When provided the following input:

$accept = [
    'application/ld+json',
    'application/json',
    'text/html', 
];

It outputs the following string:
"application/json,application/ld+json;q=0.9,text/html;q=0.8

This causes the API client to produce an empty response object because it fails to deserialize plain JSON.

openapi-generator version

master

OpenAPI declaration file content or url

Petstore example from master.

Generation Details

Petstore example from master.

Steps to reproduce

I wrote a little test using the HeaderSelector from master:
https://3v4l.org/JphEQ

$accept = [
    'application/ld+json',
    'application/json',
    'text/html', 
];

$selector = new HeaderSelector();
$headers = $selector->selectHeaders($accept, 'application/json', false);
$accept = $headers['Accept'];

var_dump($accept);
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/4636
https://github.com/OpenAPITools/openapi-generator/issues/5163
https://github.com/OpenAPITools/openapi-generator/issues/12926
https://github.com/OpenAPITools/openapi-generator/pull/4684
https://github.com/OpenAPITools/openapi-generator/pull/13844

Suggest a fix

It seems to me that application/ld+json should be preserved as the first format to accept.

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

Read samples/client/petstore/php/OpenAPIClient-php/lib/HeaderSelector.php and reproduce the supplied selectHeaders call with the listed Accept formats. Done means the generated Accept header preserves application/ld+json first instead of reordering it ahead of application/json, while confirming the reported output changes.

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
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.