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 = [];

src/Service/AppSync/src/Input/ListApiKeysRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ public function getNextToken(): ?string
8383
public function request(): Request
8484
{
8585
// Prepare headers
86-
$headers = ['content-type' => 'application/json'];
86+
$headers = [
87+
'Content-Type' => 'application/json',
88+
'Accept' => 'application/json',
89+
];
8790

8891
// Prepare query
8992
$query = [];

src/Service/AppSync/src/Input/ListResolversRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ public function getTypeName(): ?string
100100
public function request(): Request
101101
{
102102
// Prepare headers
103-
$headers = ['content-type' => 'application/json'];
103+
$headers = [
104+
'Content-Type' => 'application/json',
105+
'Accept' => 'application/json',
106+
];
104107

105108
// Prepare query
106109
$query = [];

src/Service/AppSync/src/Input/StartSchemaCreationRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ public function getDefinition(): ?string
6969
public function request(): Request
7070
{
7171
// Prepare headers
72-
$headers = ['content-type' => 'application/json'];
72+
$headers = [
73+
'Content-Type' => 'application/json',
74+
'Accept' => 'application/json',
75+
];
7376

7477
// Prepare query
7578
$query = [];

src/Service/AppSync/src/Input/UpdateApiKeyRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ public function getId(): ?string
100100
public function request(): Request
101101
{
102102
// Prepare headers
103-
$headers = ['content-type' => 'application/json'];
103+
$headers = [
104+
'Content-Type' => 'application/json',
105+
'Accept' => 'application/json',
106+
];
104107

105108
// Prepare query
106109
$query = [];

src/Service/AppSync/src/Input/UpdateDataSourceRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ public function getType(): ?string
259259
public function request(): Request
260260
{
261261
// Prepare headers
262-
$headers = ['content-type' => 'application/json'];
262+
$headers = [
263+
'Content-Type' => 'application/json',
264+
'Accept' => 'application/json',
265+
];
263266

264267
// Prepare query
265268
$query = [];

src/Service/AppSync/src/Input/UpdateResolverRequest.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/tests/Unit/Input/CreateResolverRequestTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function testRequest(): void
4343
$expected = '
4444
POST /v1/apis/apiId/types/foo/resolvers HTTP/1.1 200
4545
Content-type: application/json
46+
Accept: application/json
4647
4748
{
4849
"cachingConfig": {

src/Service/AppSync/tests/Unit/Input/DeleteResolverRequestTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public function testRequest(): void
1818
// see https://docs.aws.amazon.com/appsync/latest/APIReference/API_DeleteResolver.html
1919
$expected = '
2020
DELETE /v1/apis/api123/types/type/resolvers/field HTTP/1.1
21-
Content-Type: application/json
21+
Content-type: application/json
22+
Accept: application/json
2223
';
2324

2425
self::assertRequestEqualsHttpRequest($expected, $input->request());

src/Service/AppSync/tests/Unit/Input/GetSchemaCreationStatusRequestTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public function testRequest(): void
1616
// see https://docs.aws.amazon.com/appsync/latest/APIReference/API_GetSchemaCreationStatus.html
1717
$expected = '
1818
GET /v1/apis/api123/schemacreation HTTP/1.1
19-
Content-Type: application/json
19+
Content-type: application/json
20+
Accept: application/json
2021
';
2122

2223
self::assertRequestEqualsHttpRequest($expected, $input->request());

src/Service/AppSync/tests/Unit/Input/ListApiKeysRequestTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public function testRequest(): void
1818
// see https://docs.aws.amazon.com/appsync/latest/APIReference/API_ListApiKeys.html
1919
$expected = '
2020
GET /v1/apis/api123/apikeys?maxResults=1337&nextToken=token HTTP/1.1
21-
Content-Type: application/json
21+
Content-type: application/json
22+
Accept: application/json
2223
';
2324

2425
self::assertRequestEqualsHttpRequest($expected, $input->request());

src/Service/AppSync/tests/Unit/Input/ListResolversRequestTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public function testRequest(): void
1919
// see https://docs.aws.amazon.com/appsync/latest/APIReference/API_ListResolvers.html
2020
$expected = '
2121
GET /v1/apis/api123/types/type/resolvers?maxResults=1337&nextToken=token HTTP/1.1
22-
Content-Type: application/json
22+
Content-type: application/json
23+
Accept: application/json
2324
';
2425

2526
self::assertRequestEqualsHttpRequest($expected, $input->request());

src/Service/AppSync/tests/Unit/Input/StartSchemaCreationRequestTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function testRequest(): void
2020
$expected = '
2121
POST /v1/apis/api123/schemacreation HTTP/1.1
2222
Content-type: application/json
23+
Accept: application/json
2324
2425
{
2526
"definition": "c2NoZW1hRGVmaW5pdGlvbg=="

src/Service/AppSync/tests/Unit/Input/UpdateApiKeyRequestTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function testRequest(): void
2020
$expected = '
2121
POST /v1/apis/api123/apikeys/keyId HTTP/1.1
2222
Content-type: application/json
23+
Accept: application/json
2324
2425
{
2526
"description": "Description here",

src/Service/AppSync/tests/Unit/Input/UpdateDataSourceRequestTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function testRequest(): void
7171
$expected = '
7272
POST /v1/apis/api123/datasources/dataSourceName HTTP/1.1
7373
Content-type: application/json
74+
Accept: application/json
7475
7576
{
7677
"description": "This is a description",

src/Service/AppSync/tests/Unit/Input/UpdateResolverRequestTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function testRequest(): void
4444
$expected = '
4545
POST /v1/apis/api123/types/type/resolvers/field HTTP/1.1
4646
Content-type: application/json
47+
Accept: application/json
4748
4849
{
4950
"cachingConfig": {

src/Service/Athena/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Changed
66

7+
- Add `Accept: application/json` header in request to fix incompatibility with 3rd party providers
78
- AWS enhancement: Documentation updates.
89

910
## 2.2.0

src/Service/Athena/src/Input/GetCalculationExecutionRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function request(): Request
5555
$headers = [
5656
'Content-Type' => 'application/x-amz-json-1.1',
5757
'X-Amz-Target' => 'AmazonAthena.GetCalculationExecution',
58+
'Accept' => 'application/json',
5859
];
5960

6061
// Prepare query

src/Service/Athena/src/Input/GetCalculationExecutionStatusRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function request(): Request
5555
$headers = [
5656
'Content-Type' => 'application/x-amz-json-1.1',
5757
'X-Amz-Target' => 'AmazonAthena.GetCalculationExecutionStatus',
58+
'Accept' => 'application/json',
5859
];
5960

6061
// Prepare query

src/Service/Athena/src/Input/GetDataCatalogInput.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function request(): Request
7070
$headers = [
7171
'Content-Type' => 'application/x-amz-json-1.1',
7272
'X-Amz-Target' => 'AmazonAthena.GetDataCatalog',
73+
'Accept' => 'application/json',
7374
];
7475

7576
// Prepare query

src/Service/Athena/src/Input/GetDatabaseInput.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function request(): Request
8888
$headers = [
8989
'Content-Type' => 'application/x-amz-json-1.1',
9090
'X-Amz-Target' => 'AmazonAthena.GetDatabase',
91+
'Accept' => 'application/json',
9192
];
9293

9394
// Prepare query

src/Service/Athena/src/Input/GetNamedQueryInput.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function request(): Request
5555
$headers = [
5656
'Content-Type' => 'application/x-amz-json-1.1',
5757
'X-Amz-Target' => 'AmazonAthena.GetNamedQuery',
58+
'Accept' => 'application/json',
5859
];
5960

6061
// Prepare query

src/Service/Athena/src/Input/GetQueryExecutionInput.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function request(): Request
5555
$headers = [
5656
'Content-Type' => 'application/x-amz-json-1.1',
5757
'X-Amz-Target' => 'AmazonAthena.GetQueryExecution',
58+
'Accept' => 'application/json',
5859
];
5960

6061
// Prepare query

src/Service/Athena/src/Input/GetQueryResultsInput.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function request(): Request
8787
$headers = [
8888
'Content-Type' => 'application/x-amz-json-1.1',
8989
'X-Amz-Target' => 'AmazonAthena.GetQueryResults',
90+
'Accept' => 'application/json',
9091
];
9192

9293
// Prepare query

src/Service/Athena/src/Input/GetSessionRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function request(): Request
5555
$headers = [
5656
'Content-Type' => 'application/x-amz-json-1.1',
5757
'X-Amz-Target' => 'AmazonAthena.GetSession',
58+
'Accept' => 'application/json',
5859
];
5960

6061
// Prepare query

src/Service/Athena/src/Input/GetSessionStatusRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function request(): Request
5555
$headers = [
5656
'Content-Type' => 'application/x-amz-json-1.1',
5757
'X-Amz-Target' => 'AmazonAthena.GetSessionStatus',
58+
'Accept' => 'application/json',
5859
];
5960

6061
// Prepare query

src/Service/Athena/src/Input/GetTableMetadataInput.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function request(): Request
105105
$headers = [
106106
'Content-Type' => 'application/x-amz-json-1.1',
107107
'X-Amz-Target' => 'AmazonAthena.GetTableMetadata',
108+
'Accept' => 'application/json',
108109
];
109110

110111
// Prepare query

src/Service/Athena/src/Input/GetWorkGroupInput.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function request(): Request
5555
$headers = [
5656
'Content-Type' => 'application/x-amz-json-1.1',
5757
'X-Amz-Target' => 'AmazonAthena.GetWorkGroup',
58+
'Accept' => 'application/json',
5859
];
5960

6061
// Prepare query

0 commit comments

Comments
 (0)