Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/PSR7/OperationAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class OperationAddress
protected $method;
/** @var string */
protected $path;
/** @var string */
protected $fullPath;

public function __construct(string $path, string $method)
{
Expand Down Expand Up @@ -63,6 +65,18 @@ public function path(): string
return $this->path;
}

public function fullPath(): string
{
return $this->fullPath;
}

public function setFullPath(string $fullPath): self
{
$this->fullPath = $fullPath;

return $this;
}

public function hasPlaceholders(): bool
{
return (bool) $this->countPlaceholders();
Expand All @@ -76,7 +90,7 @@ public function countPlaceholders(): int
public function countExactMatchParts(string $comparisonPath): int
{
$comparisonPathParts = explode('/', trim($comparisonPath, '/'));
$pathParts = explode('/', trim($this->path(), '/'));
$pathParts = explode('/', trim($this->fullPath(), '/'));
$exactMatchCount = 0;
foreach ($comparisonPathParts as $key => $comparisonPathPart) {
if ($comparisonPathPart !== $pathParts[$key]) {
Expand Down
4 changes: 2 additions & 2 deletions src/PSR7/PathFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private function doSearch(): array
}

// path matched!
$paths[] = $opCandidate['addr'];
$paths[] = $opCandidate['addr']->setFullPath($candidatePath);
break;
}
}
Expand Down Expand Up @@ -230,7 +230,7 @@ private function attemptNarrowDown(array $paths): array
$partCounts = [];
$placeholderCounts = [];
foreach ($paths as $path) {
$partCounts[] = $this->countParts($path->path());
$partCounts[] = $this->countParts($path->fullPath());
$placeholderCounts[] = $path->countPlaceholders();
}

Expand Down
4 changes: 3 additions & 1 deletion tests/PSR7/PathFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public function testItPrioritisesOperatorsThatAreMoreStatic(): void
title: Uber API
description: Move your app forward with the Uber API
version: "1.0.0"
servers:
- url: https://localhost/v1
paths:
/products/{product}/images/{image}:
get:
Expand All @@ -134,7 +136,7 @@ public function testItPrioritisesOperatorsThatAreMoreStatic(): void
summary: All thumbnail images for a specific product
SPEC;

$pathFinder = new PathFinder(Reader::readFromYaml($spec), '/products/10/images/thumbnails', 'get');
$pathFinder = new PathFinder(Reader::readFromYaml($spec), '/v1/products/10/images/thumbnails', 'get');
$opAddrs = $pathFinder->search();

$this->assertCount(1, $opAddrs);
Expand Down