Skip to content

Commit

Permalink
Add support for maps as querystrings
Browse files Browse the repository at this point in the history
  • Loading branch information
jeskew committed Sep 30, 2015
1 parent 5358837 commit fa9ac14
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Api/Serializer/RestSerializer.php
@@ -1,6 +1,7 @@
<?php
namespace Aws\Api\Serializer;

use Aws\Api\MapShape;
use Aws\Api\Service;
use Aws\Api\Operation;
use Aws\Api\Shape;
Expand Down Expand Up @@ -140,7 +141,11 @@ private function applyHeaderMap($name, Shape $member, array $value, array &$opts

private function applyQuery($name, Shape $member, $value, array &$opts)
{
if ($value !== null) {
if ($member instanceof MapShape) {
$opts['query'] = isset($opts['query']) && is_array($opts['query'])
? $opts['query'] + $value
: $value;
} elseif ($value !== null) {
$opts['query'][$member['locationName'] ?: $name] = $value;
}
}
Expand Down
126 changes: 126 additions & 0 deletions tests/Api/test_cases/protocols/input/rest-json.json
Expand Up @@ -86,6 +86,132 @@
}
]
},
{
"description": "String to string maps in querystring",
"metadata": {
"protocol": "rest-json",
"apiVersion": "2014-01-01"
},
"shapes": {
"InputShape": {
"type": "structure",
"members": {
"PipelineId": {
"shape": "StringType",
"location": "uri"
},
"QueryDoc": {
"shape": "MapStringStringType",
"location": "querystring"
}
}
},
"MapStringStringType": {
"type": "map",
"key": {
"shape": "StringType"
},
"value": {
"shape": "StringType"
}
},
"StringType": {
"type": "string"
}
},
"cases": [
{
"given": {
"http": {
"method": "GET",
"requestUri": "/2014-01-01/jobsByPipeline/{PipelineId}"
},
"input": {
"shape": "InputShape"
},
"name": "OperationName"
},
"params": {
"PipelineId": "foo",
"QueryDoc": {
"bar": "baz",
"fizz": "buzz"
}
},
"serialized": {
"body": "",
"uri": "/2014-01-01/jobsByPipeline/foo?bar=baz&fizz=buzz",
"headers": {}
}
}
]
},
{
"description": "String to string list maps in querystring",
"metadata": {
"protocol": "rest-json",
"apiVersion": "2014-01-01"
},
"shapes": {
"InputShape": {
"type": "structure",
"members": {
"PipelineId": {
"shape": "StringType",
"location": "uri"
},
"QueryDoc": {
"shape": "MapStringStringListType",
"location": "querystring"
}
}
},
"MapStringStringListType": {
"type": "map",
"key": {
"shape": "StringType"
},
"value": {
"shape": "StringListType"
}
},
"StringListType": {
"type": "list",
"member": {
"shape": "StringType"
}
},
"StringType": {
"type": "string"
}
},
"cases": [
{
"given": {
"http": {
"method": "GET",
"requestUri": "/2014-01-01/jobsByPipeline/{PipelineId}"
},
"input": {
"shape": "InputShape"
},
"name": "OperationName"
},
"params": {
"PipelineId": "id",
"QueryDoc": {
"foo": ["bar", "baz"],
"fizz": ["buzz", "pop"]
}
},
"serialized": {
"body": "",
"uri": "/2014-01-01/jobsByPipeline/id?foo=bar&foo=baz&fizz=buzz&fizz=pop",
"headers": {}
}
}
]
},
{
"description": "URI parameter and querystring params",
"metadata": {
Expand Down
126 changes: 126 additions & 0 deletions tests/Api/test_cases/protocols/input/rest-xml.json
Expand Up @@ -679,6 +679,132 @@
}
]
},
{
"description": "String to string maps in querystring",
"metadata": {
"protocol": "rest-xml",
"apiVersion": "2014-01-01"
},
"shapes": {
"InputShape": {
"type": "structure",
"members": {
"PipelineId": {
"shape": "StringType",
"location": "uri"
},
"QueryDoc": {
"shape": "MapStringStringType",
"location": "querystring"
}
}
},
"MapStringStringType": {
"type": "map",
"key": {
"shape": "StringType"
},
"value": {
"shape": "StringType"
}
},
"StringType": {
"type": "string"
}
},
"cases": [
{
"given": {
"http": {
"method": "GET",
"requestUri": "/2014-01-01/jobsByPipeline/{PipelineId}"
},
"input": {
"shape": "InputShape"
},
"name": "OperationName"
},
"params": {
"PipelineId": "foo",
"QueryDoc": {
"bar": "baz",
"fizz": "buzz"
}
},
"serialized": {
"body": "",
"uri": "/2014-01-01/jobsByPipeline/foo?bar=baz&fizz=buzz",
"headers": {}
}
}
]
},
{
"description": "String to string list maps in querystring",
"metadata": {
"protocol": "rest-xml",
"apiVersion": "2014-01-01"
},
"shapes": {
"InputShape": {
"type": "structure",
"members": {
"PipelineId": {
"shape": "StringType",
"location": "uri"
},
"QueryDoc": {
"shape": "MapStringStringListType",
"location": "querystring"
}
}
},
"MapStringStringListType": {
"type": "map",
"key": {
"shape": "StringType"
},
"value": {
"shape": "StringListType"
}
},
"StringListType": {
"type": "list",
"member": {
"shape": "StringType"
}
},
"StringType": {
"type": "string"
}
},
"cases": [
{
"given": {
"http": {
"method": "GET",
"requestUri": "/2014-01-01/jobsByPipeline/{PipelineId}"
},
"input": {
"shape": "InputShape"
},
"name": "OperationName"
},
"params": {
"PipelineId": "id",
"QueryDoc": {
"foo": ["bar", "baz"],
"fizz": ["buzz", "pop"]
}
},
"serialized": {
"body": "",
"uri": "/2014-01-01/jobsByPipeline/id?foo=bar&foo=baz&fizz=buzz&fizz=pop",
"headers": {}
}
}
]
},
{
"description": "String payload",
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion tests/Integ/SmokeContext.php
Expand Up @@ -345,7 +345,7 @@ public function theErrorCodeShouldBe($errorCode, PyStringNode $string = null)
*/
public function theRequestShouldBeSuccessful()
{
throw new PendingException();
$this->assertEmpty($this->error);
}

/**
Expand Down

0 comments on commit fa9ac14

Please sign in to comment.