Skip to content

Commit

Permalink
fix(php): call selectHeaders correctly in psr-18 implementation (#17832)
Browse files Browse the repository at this point in the history
- `selectHeadersForMultipart()` does not exist,
- therefore we have to call `selectHeaders()`

This is signature of `public function selectHeaders(array $accept, string $contentType, bool $isMultipart): array;`

We have to pass `$multipart` as 3rd parameter.

The second parameter is content type as string, not in array.
  • Loading branch information
simPod committed Feb 12, 2024
1 parent 5535578 commit cd23dfd
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 470 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -605,16 +605,11 @@ use function sprintf;
}
{{/formParams}}

if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
[{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}]
);
} else {
$headers = $this->headerSelector->selectHeaders(
[{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}],
[{{#consumes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}]
);
}
$headers = $this->headerSelector->selectHeaders(
[{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}],
'{{#consumes}}{{{mediaType}}}{{/consumes}}',
$multipart
);

// for model (json/xml)
{{#bodyParams}}
Expand Down
15 changes: 5 additions & 10 deletions samples/client/petstore/php/psr-18/lib/Api/AnotherFakeApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,16 +369,11 @@ public function call123TestSpecialTagsRequest($client)



if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
['application/json']
);
} else {
$headers = $this->headerSelector->selectHeaders(
['application/json'],
['application/json']
);
}
$headers = $this->headerSelector->selectHeaders(
['application/json'],
'application/json',
$multipart
);

// for model (json/xml)
if (isset($client)) {
Expand Down
15 changes: 5 additions & 10 deletions samples/client/petstore/php/psr-18/lib/Api/DefaultApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,11 @@ public function fooGetRequest()



if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
['application/json']
);
} else {
$headers = $this->headerSelector->selectHeaders(
['application/json'],
[]
);
}
$headers = $this->headerSelector->selectHeaders(
['application/json'],
'',
$multipart
);

// for model (json/xml)
if (count($formParams) > 0) {
Expand Down
Loading

0 comments on commit cd23dfd

Please sign in to comment.