diff --git a/RouteDescriber/RouteMetadataDescriber.php b/RouteDescriber/RouteMetadataDescriber.php index 83d80685e..5f916e545 100644 --- a/RouteDescriber/RouteMetadataDescriber.php +++ b/RouteDescriber/RouteMetadataDescriber.php @@ -68,7 +68,7 @@ public function describe(OA\OpenApi $api, Route $route, \ReflectionMethod $refle } // add the pattern anyway if (Generator::UNDEFINED === $parameter->schema->pattern) { - $parameter->schema->pattern = $requirements[$pathVariable]; + $parameter->schema->pattern = sprintf('^(?:%s)$', $requirements[$pathVariable]); } } } diff --git a/Tests/Functional/Controller/ApiController80.php b/Tests/Functional/Controller/ApiController80.php index a570ebf53..80a9ebf51 100644 --- a/Tests/Functional/Controller/ApiController80.php +++ b/Tests/Functional/Controller/ApiController80.php @@ -113,7 +113,7 @@ public function implicitSwaggerAction() } /** - * @Route("/test/users/{user}", methods={"POST"}, schemes={"https"}, requirements={"user"="/foo/"}) + * @Route("/test/users/{user}", methods={"POST"}, schemes={"https"}, requirements={"user"="foo"}) * @OA\Response( * response="201", * description="Operation automatically detected", @@ -129,7 +129,7 @@ public function submitUserTypeAction() } /** - * @Route("/test/{user}", methods={"GET"}, schemes={"https"}, requirements={"user"="/foo/"}) + * @Route("/test/{user}", methods={"GET"}, schemes={"https"}, requirements={"user"="foo"}) * @OA\Response(response=200, description="sucessful") */ public function userAction() diff --git a/Tests/Functional/FunctionalTest.php b/Tests/Functional/FunctionalTest.php index 7c9bb784d..57251948a 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -147,7 +147,7 @@ public function testUserAction() $parameter = Util::getOperationParameter($operation, 'user', 'path'); $this->assertTrue($parameter->required); $this->assertEquals('string', $parameter->schema->type); - $this->assertEquals('/foo/', $parameter->schema->pattern); + $this->assertEquals('^(?:foo)$', $parameter->schema->pattern); $this->assertEquals(Generator::UNDEFINED, $parameter->schema->format); } diff --git a/Tests/RouteDescriber/RouteMetadataDescriberTest.php b/Tests/RouteDescriber/RouteMetadataDescriberTest.php index c8f61b98d..798d5c0d2 100644 --- a/Tests/RouteDescriber/RouteMetadataDescriberTest.php +++ b/Tests/RouteDescriber/RouteMetadataDescriberTest.php @@ -44,7 +44,7 @@ public function testRouteRequirementsWithPattern() $this->assertEquals('path', $getPathParameter->in); $this->assertEquals('foo', $getPathParameter->name); $this->assertEquals('string', $getPathParameter->schema->type); - $this->assertEquals('[0-9]|[a-z]', $getPathParameter->schema->pattern); + $this->assertEquals('^(?:[0-9]|[a-z])$', $getPathParameter->schema->pattern); } } @@ -68,7 +68,7 @@ public function testSimpleOrRequirementsAreHandledAsEnums($req) $this->assertEquals('foo', $getPathParameter->name); $this->assertEquals('string', $getPathParameter->schema->type); $this->assertEquals(explode('|', $req), $getPathParameter->schema->enum); - $this->assertEquals($req, $getPathParameter->schema->pattern); + $this->assertEquals('^(?:' . $req . ')$', $getPathParameter->schema->pattern); } /** @@ -86,7 +86,7 @@ public function testNonEnumPatterns($pattern) ); $getPathParameter = $api->paths[0]->get->parameters[0]; - $this->assertEquals($pattern, $getPathParameter->schema->pattern); + $this->assertEquals('^(?:' . $pattern . ')$', $getPathParameter->schema->pattern); $this->assertEquals(Generator::UNDEFINED, $getPathParameter->schema->enum); }