Skip to content

Commit

Permalink
fix endpoint path removal (#1795)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chase Coalwell committed May 22, 2019
1 parent 96fd506 commit 880f442
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changes/nextrelease/changelog_endpoint_path.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "bugfix",
"category": "Api",
"description": "Preserve path on custom endpoints"
}
]
6 changes: 6 additions & 0 deletions src/Api/Serializer/RestSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ function (array $matches) use ($varspecs) {
$relative .= strpos($relative, '?') ? "&{$append}" : "?$append";
}

// If endpoint has path, remove leading '/' to preserve URI resolution.
$path = $this->endpoint->getPath();
if ($path && $relative[0] === '/') {
$relative = substr($relative, 1);
}

// Expand path place holders using Amazon's slightly different URI
// template syntax.
return UriResolver::resolve($this->endpoint, new Uri($relative));
Expand Down
20 changes: 20 additions & 0 deletions tests/Api/Serializer/RestJsonSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ private function getRequest($commandName, $input)
return $j($command);
}

private function getPathEndpointRequest($commandName, $input)
{
$service = $this->getTestService();
$command = new Command($commandName, $input);
$j = new RestJsonSerializer($service, 'http://foo.com/bar');
return $j($command);
}

public function testPreparesRequestsWithContentType()
{
$request = $this->getRequest('foo', ['baz' => 'bar']);
Expand All @@ -98,6 +106,18 @@ public function testPreparesRequestsWithContentType()
);
}

public function testPreparesRequestsWithEndpointWithPath()
{
$request = $this->getPathEndpointRequest('foo', ['baz' => 'bar']);
$this->assertEquals('POST', $request->getMethod());
$this->assertEquals('http://foo.com/bar', (string) $request->getUri());
$this->assertEquals('{"baz":"bar"}', (string) $request->getBody());
$this->assertEquals(
'application/json',
$request->getHeaderLine('Content-Type')
);
}

public function testPreparesRequestsWithBlobButNoForcedContentType()
{
$request = $this->getRequest('bar', ['baz' => 'bar']);
Expand Down

0 comments on commit 880f442

Please sign in to comment.