-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prioritize full match paths in PathFinder
- Loading branch information
Showing
3 changed files
with
179 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace League\OpenAPIValidation\Tests\FromCommunity; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use League\OpenAPIValidation\PSR7\OperationAddress; | ||
use League\OpenAPIValidation\PSR7\ValidatorBuilder; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class RouteCollisionIssueTest extends TestCase | ||
{ | ||
public function testRouteCollisionIsHandlerProperly(): void | ||
{ | ||
$schema = /** @lang JSON */ | ||
' | ||
{ | ||
"openapi": "3.0.0", | ||
"info": { | ||
"description": "", | ||
"version": "1.0.0", | ||
"title": "Apples" | ||
}, | ||
"servers": [ | ||
{ | ||
"url": "/api" | ||
} | ||
], | ||
"paths": { | ||
"/apples/{apple_id}": { | ||
"get": { | ||
"summary": "", | ||
"description": "", | ||
"operationId": "appleGet", | ||
"parameters": [ | ||
{ | ||
"in": "path", | ||
"name": "apple_id", | ||
"schema": { | ||
"type": "integer" | ||
}, | ||
"required": true | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "Success", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "object", | ||
"required": [ | ||
"apple" | ||
], | ||
"properties": { | ||
"apple": { | ||
"$ref": "#/components/schemas/apple" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/apples/ready-to-eat": { | ||
"get": { | ||
"summary": "", | ||
"description": "", | ||
"operationId": "applesReadyGet", | ||
"responses": { | ||
"200": { | ||
"description": "Success", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"properties": { | ||
"apples": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/components/schemas/apple" | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"apples" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"apple": { | ||
"type": "object", | ||
"required": [ | ||
"id" | ||
], | ||
"properties": { | ||
"id": { | ||
"type": "integer" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
'; | ||
|
||
$validator = (new ValidatorBuilder())->fromJson($schema)->getResponseValidator(); | ||
$operation = new OperationAddress('/api/apples/ready-to-eat', 'get'); | ||
|
||
$responseContent = /** @lang JSON */ | ||
' | ||
{ | ||
"apples": [ | ||
{ | ||
"id": 0 | ||
} | ||
] | ||
} | ||
'; | ||
|
||
$response = new Response(200, ['Content-Type' => 'application/json'], $responseContent); | ||
|
||
$validator->validate($operation, $response); | ||
|
||
$this->addToAssertionCount(1); | ||
} | ||
} |