Skip to content

Commit

Permalink
Add an accept header in JSON request to help 3rd party services like …
Browse files Browse the repository at this point in the history
…localstack
  • Loading branch information
jderusse committed Jun 3, 2024
1 parent f840c9c commit 37c60a6
Show file tree
Hide file tree
Showing 269 changed files with 563 additions and 78 deletions.
4 changes: 2 additions & 2 deletions src/CodeGenerator/src/Generator/InputGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ private function inputClassRequestGetters(StructureShape $inputShape, ClassBuild
$serializer = $this->serializer->get($operation->getService());

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

$body['querystring'] = '$query = [];' . "\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
*/
class JsonRpcSerializer extends RestJsonSerializer
{
public function getHeaders(Operation $operation): string
public function getHeaders(Operation $operation, bool $withPayload): string
{
return strtr(<<<PHP
[
'Content-Type' => 'application/x-amz-json-VERSION',
'X-Amz-Target' => 'TARGET',
];
if (!$withPayload) {
return "['Accept' => 'application/json']";
}

PHP
, [
'VERSION' => number_format($operation->getService()->getJsonVersion(), 1),
'TARGET' => sprintf('%s.%s', $operation->getService()->getTargetPrefix(), $operation->getName()),
]);
return strtr("[
'Content-Type' => 'application/x-amz-json-VERSION',
'X-Amz-Target' => 'TARGET',
'Accept' => 'application/json',
]", [
'VERSION' => number_format($operation->getService()->getJsonVersion(), 1),
'TARGET' => sprintf('%s.%s', $operation->getService()->getTargetPrefix(), $operation->getName()),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ public function __construct(NamespaceRegistry $namespaceRegistry, RequirementsRe
$this->requirementsRegistry = $requirementsRegistry;
}

public function getHeaders(Operation $operation): string
public function getHeaders(Operation $operation, bool $withPayload): string
{
return '["content-type" => "application/x-www-form-urlencoded"]';
if (!$withPayload) {
return '[]';
}

return "['content-type' => 'application/x-www-form-urlencoded']";
}

public function generateRequestBody(Operation $operation, StructureShape $shape): SerializerResultBody
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,16 @@ public function __construct(NamespaceRegistry $namespaceRegistry, RequirementsRe
$this->requirementsRegistry = $requirementsRegistry;
}

public function getHeaders(Operation $operation): string
public function getHeaders(Operation $operation, bool $withPayload): string
{
return '["content-type" => "application/json"]';
if (!$withPayload) {
return "['Accept' => 'application/json']";
}

return "[
'Content-Type' => 'application/json',
'Accept' => 'application/json',
]";
}

public function generateRequestBody(Operation $operation, StructureShape $shape): SerializerResultBody
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ public function __construct(NamespaceRegistry $namespaceRegistry, RequirementsRe
$this->requirementsRegistry = $requirementsRegistry;
}

public function getHeaders(Operation $operation): string
public function getHeaders(Operation $operation, bool $withPayload): string
{
return '["content-type" => "application/xml"]';
if (!$withPayload) {
return '[]';
}

return "['content-type' => 'application/xml']";
}

public function generateRequestBody(Operation $operation, StructureShape $shape): SerializerResultBody
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ public function generateRequestBody(Operation $operation, StructureShape $shape)
*/
public function generateRequestBuilder(StructureShape $shape, bool $needsChecks): SerializerResultBuilder;

public function getHeaders(Operation $operation): string;
public function getHeaders(Operation $operation, bool $withPayload): string;
}
4 changes: 4 additions & 0 deletions src/Service/AppSync/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## NOT RELEASED

### Changed

- Add `Accept: application/json` header in request to fix incompatibility with 3rd party providers

## 2.1.0

### Added
Expand Down
5 changes: 4 additions & 1 deletion src/Service/AppSync/src/Input/CreateResolverRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ public function getTypeName(): ?string
public function request(): Request
{
// Prepare headers
$headers = ['content-type' => 'application/json'];
$headers = [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
];

// Prepare query
$query = [];
Expand Down
5 changes: 4 additions & 1 deletion src/Service/AppSync/src/Input/DeleteResolverRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ public function getTypeName(): ?string
public function request(): Request
{
// Prepare headers
$headers = ['content-type' => 'application/json'];
$headers = [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
];

// Prepare query
$query = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public function getApiId(): ?string
public function request(): Request
{
// Prepare headers
$headers = ['content-type' => 'application/json'];
$headers = [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
];

// Prepare query
$query = [];
Expand Down
5 changes: 4 additions & 1 deletion src/Service/AppSync/src/Input/ListApiKeysRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ public function getNextToken(): ?string
public function request(): Request
{
// Prepare headers
$headers = ['content-type' => 'application/json'];
$headers = [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
];

// Prepare query
$query = [];
Expand Down
5 changes: 4 additions & 1 deletion src/Service/AppSync/src/Input/ListResolversRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ public function getTypeName(): ?string
public function request(): Request
{
// Prepare headers
$headers = ['content-type' => 'application/json'];
$headers = [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
];

// Prepare query
$query = [];
Expand Down
5 changes: 4 additions & 1 deletion src/Service/AppSync/src/Input/StartSchemaCreationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ public function getDefinition(): ?string
public function request(): Request
{
// Prepare headers
$headers = ['content-type' => 'application/json'];
$headers = [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
];

// Prepare query
$query = [];
Expand Down
5 changes: 4 additions & 1 deletion src/Service/AppSync/src/Input/UpdateApiKeyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ public function getId(): ?string
public function request(): Request
{
// Prepare headers
$headers = ['content-type' => 'application/json'];
$headers = [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
];

// Prepare query
$query = [];
Expand Down
5 changes: 4 additions & 1 deletion src/Service/AppSync/src/Input/UpdateDataSourceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ public function getType(): ?string
public function request(): Request
{
// Prepare headers
$headers = ['content-type' => 'application/json'];
$headers = [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
];

// Prepare query
$query = [];
Expand Down
5 changes: 4 additions & 1 deletion src/Service/AppSync/src/Input/UpdateResolverRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ public function getTypeName(): ?string
public function request(): Request
{
// Prepare headers
$headers = ['content-type' => 'application/json'];
$headers = [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
];

// Prepare query
$query = [];
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Changed

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

## 2.2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.GetCalculationExecution',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.GetCalculationExecutionStatus',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/GetDataCatalogInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.GetDataCatalog',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/GetDatabaseInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.GetDatabase',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/GetNamedQueryInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.GetNamedQuery',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/GetQueryExecutionInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.GetQueryExecution',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/GetQueryResultsInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.GetQueryResults',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/GetSessionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.GetSession',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/GetSessionStatusRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.GetSessionStatus',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/GetTableMetadataInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.GetTableMetadata',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/GetWorkGroupInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.GetWorkGroup',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/ListDatabasesInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.ListDatabases',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/ListNamedQueriesInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.ListNamedQueries',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/ListQueryExecutionsInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.ListQueryExecutions',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/ListTableMetadataInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.ListTableMetadata',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.StartCalculationExecution',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/StartQueryExecutionInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.StartQueryExecution',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/StartSessionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.StartSession',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.StopCalculationExecution',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/StopQueryExecutionInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.StopQueryExecution',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
1 change: 1 addition & 0 deletions src/Service/Athena/src/Input/TerminateSessionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function request(): Request
$headers = [
'Content-Type' => 'application/x-amz-json-1.1',
'X-Amz-Target' => 'AmazonAthena.TerminateSession',
'Accept' => 'application/json',
];

// Prepare query
Expand Down
Loading

0 comments on commit 37c60a6

Please sign in to comment.