Skip to content

Commit f7f8bca

Browse files
authored
Add an accept header in JSON request to help 3rd party services like localstack (#1721)
1 parent b53ae32 commit f7f8bca

File tree

500 files changed

+881
-170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

500 files changed

+881
-170
lines changed

src/CodeGenerator/src/Generator/InputGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,9 @@ private function inputClassRequestGetters(StructureShape $inputShape, ClassBuild
389389
$serializer = $this->serializer->get($operation->getService());
390390

391391
if ((null !== $payloadProperty = $inputShape->getPayload()) && $inputShape->getMember($payloadProperty)->isStreaming()) {
392-
$body['header'] = '$headers = [];' . "\n";
392+
$body['header'] = '$headers = ' . $serializer->getHeaders($operation, false) . ';' . "\n";
393393
} else {
394-
$body['header'] = '$headers = ' . $serializer->getHeaders($operation) . ';' . "\n";
394+
$body['header'] = '$headers = ' . $serializer->getHeaders($operation, true) . ';' . "\n";
395395
}
396396

397397
$body['querystring'] = '$query = [];' . "\n";

src/CodeGenerator/src/Generator/RequestSerializer/JsonRpcSerializer.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@
1515
*/
1616
class JsonRpcSerializer extends RestJsonSerializer
1717
{
18-
public function getHeaders(Operation $operation): string
18+
public function getHeaders(Operation $operation, bool $withPayload): string
1919
{
20-
return strtr(<<<PHP
21-
[
22-
'Content-Type' => 'application/x-amz-json-VERSION',
23-
'X-Amz-Target' => 'TARGET',
24-
];
20+
if (!$withPayload) {
21+
return "['Accept' => 'application/json']";
22+
}
2523

26-
PHP
27-
, [
28-
'VERSION' => number_format($operation->getService()->getJsonVersion(), 1),
29-
'TARGET' => sprintf('%s.%s', $operation->getService()->getTargetPrefix(), $operation->getName()),
30-
]);
24+
return strtr("[
25+
'Content-Type' => 'application/x-amz-json-VERSION',
26+
'X-Amz-Target' => 'TARGET',
27+
'Accept' => 'application/json',
28+
]", [
29+
'VERSION' => number_format($operation->getService()->getJsonVersion(), 1),
30+
'TARGET' => sprintf('%s.%s', $operation->getService()->getTargetPrefix(), $operation->getName()),
31+
]);
3132
}
3233
}

src/CodeGenerator/src/Generator/RequestSerializer/QuerySerializer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ public function __construct(NamespaceRegistry $namespaceRegistry, RequirementsRe
4343
$this->requirementsRegistry = $requirementsRegistry;
4444
}
4545

46-
public function getHeaders(Operation $operation): string
46+
public function getHeaders(Operation $operation, bool $withPayload): string
4747
{
48-
return '["content-type" => "application/x-www-form-urlencoded"]';
48+
if (!$withPayload) {
49+
return '[]';
50+
}
51+
52+
return "['content-type' => 'application/x-www-form-urlencoded']";
4953
}
5054

5155
public function generateRequestBody(Operation $operation, StructureShape $shape): SerializerResultBody

src/CodeGenerator/src/Generator/RequestSerializer/RestJsonSerializer.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,16 @@ public function __construct(NamespaceRegistry $namespaceRegistry, RequirementsRe
4343
$this->requirementsRegistry = $requirementsRegistry;
4444
}
4545

46-
public function getHeaders(Operation $operation): string
46+
public function getHeaders(Operation $operation, bool $withPayload): string
4747
{
48-
return '["content-type" => "application/json"]';
48+
if (!$withPayload) {
49+
return "['Accept' => 'application/json']";
50+
}
51+
52+
return "[
53+
'Content-Type' => 'application/json',
54+
'Accept' => 'application/json',
55+
]";
4956
}
5057

5158
public function generateRequestBody(Operation $operation, StructureShape $shape): SerializerResultBody

src/CodeGenerator/src/Generator/RequestSerializer/RestXmlSerializer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ public function __construct(NamespaceRegistry $namespaceRegistry, RequirementsRe
4040
$this->requirementsRegistry = $requirementsRegistry;
4141
}
4242

43-
public function getHeaders(Operation $operation): string
43+
public function getHeaders(Operation $operation, bool $withPayload): string
4444
{
45-
return '["content-type" => "application/xml"]';
45+
if (!$withPayload) {
46+
return '[]';
47+
}
48+
49+
return "['content-type' => 'application/xml']";
4650
}
4751

4852
public function generateRequestBody(Operation $operation, StructureShape $shape): SerializerResultBody

src/CodeGenerator/src/Generator/RequestSerializer/Serializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ public function generateRequestBody(Operation $operation, StructureShape $shape)
2727
*/
2828
public function generateRequestBuilder(StructureShape $shape, bool $needsChecks): SerializerResultBuilder;
2929

30-
public function getHeaders(Operation $operation): string;
30+
public function getHeaders(Operation $operation, bool $withPayload): string;
3131
}

src/Service/AppSync/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## NOT RELEASED
44

5+
### Changed
6+
7+
- Add `Accept: application/json` header in request to fix incompatibility with 3rd party providers
8+
59
## 2.1.0
610

711
### Added

src/Service/AppSync/src/Input/CreateResolverRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,10 @@ public function getTypeName(): ?string
278278
public function request(): Request
279279
{
280280
// Prepare headers
281-
$headers = ['content-type' => 'application/json'];
281+
$headers = [
282+
'Content-Type' => 'application/json',
283+
'Accept' => 'application/json',
284+
];
282285

283286
// Prepare query
284287
$query = [];

src/Service/AppSync/src/Input/DeleteResolverRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ public function getTypeName(): ?string
8686
public function request(): Request
8787
{
8888
// Prepare headers
89-
$headers = ['content-type' => 'application/json'];
89+
$headers = [
90+
'Content-Type' => 'application/json',
91+
'Accept' => 'application/json',
92+
];
9093

9194
// Prepare query
9295
$query = [];

src/Service/AppSync/src/Input/GetSchemaCreationStatusRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public function getApiId(): ?string
5252
public function request(): Request
5353
{
5454
// Prepare headers
55-
$headers = ['content-type' => 'application/json'];
55+
$headers = [
56+
'Content-Type' => 'application/json',
57+
'Accept' => 'application/json',
58+
];
5659

5760
// Prepare query
5861
$query = [];

0 commit comments

Comments
 (0)