Skip to content

Commit be38dc5

Browse files
committed
add tests
1 parent 7c0dab2 commit be38dc5

11 files changed

Lines changed: 556 additions & 1 deletion

File tree

src/OpenApiRouteLoader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ private function createRoute(Operation $operation, string $controller): Route
9595
if ($formatSuffix) {
9696
$formatPattern = $operation->x['format-pattern'] ?? $this->defaultFormatPattern;
9797
$route->setDefault('_format', null);
98-
$route->setRequirement('_format', $formatPattern);
98+
99+
if (null !== $formatPattern) {
100+
$route->setRequirement('_format', $formatPattern);
101+
}
99102
}
100103
if (null !== $operation->parameters) {
101104
foreach ($operation->parameters as $parameter) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\Basic;
6+
7+
use Swagger\Annotations as SWG;
8+
9+
/**
10+
* @SWG\Swagger(
11+
* @SWG\Info(
12+
* title="My API",
13+
* version="1.0"
14+
* )
15+
* )
16+
*/
17+
class Controller
18+
{
19+
/**
20+
* @SWG\Get(
21+
* path="/foobar",
22+
* @SWG\Response(
23+
* response="200",
24+
* description="Success",
25+
* )
26+
* )
27+
*/
28+
public function __invoke(): void
29+
{
30+
}
31+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\FormatSuffix;
6+
7+
use Swagger\Annotations as SWG;
8+
9+
/**
10+
* @SWG\Swagger(
11+
* @SWG\Info(
12+
* title="My API",
13+
* version="1.0"
14+
* )
15+
* )
16+
*/
17+
class Controller
18+
{
19+
/**
20+
* @SWG\Get(
21+
* path="/a",
22+
* @SWG\Response(
23+
* response="200",
24+
* description="Success",
25+
* )
26+
* )
27+
*/
28+
public function inheritEnabledFormatSuffix(): void
29+
{
30+
}
31+
32+
/**
33+
* @SWG\Get(
34+
* path="/b",
35+
* x={"format-pattern": "json|xml"},
36+
* @SWG\Response(
37+
* response="200",
38+
* description="Success",
39+
* )
40+
* )
41+
*/
42+
public function defineFormatPattern(): void
43+
{
44+
}
45+
46+
/**
47+
* @SWG\Get(
48+
* path="/c",
49+
* x={"format-suffix": false},
50+
* @SWG\Response(
51+
* response="200",
52+
* description="Success",
53+
* )
54+
* )
55+
*/
56+
public function disableFormatSuffix(): void
57+
{
58+
}
59+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\OperationId;
6+
7+
use Swagger\Annotations as SWG;
8+
9+
/**
10+
* @SWG\Swagger(
11+
* @SWG\Info(
12+
* title="My API",
13+
* version="1.0"
14+
* )
15+
* )
16+
*/
17+
class Controller
18+
{
19+
/**
20+
* @SWG\Get(
21+
* path="/foobar",
22+
* operationId="my-name",
23+
* @SWG\Response(
24+
* response="200",
25+
* description="Success",
26+
* )
27+
* )
28+
*/
29+
public function __invoke(): void
30+
{
31+
}
32+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\PathParameterPattern;
6+
7+
use Swagger\Annotations as SWG;
8+
9+
/**
10+
* @SWG\Swagger(
11+
* @SWG\Info(
12+
* title="My API",
13+
* version="1.0"
14+
* )
15+
* )
16+
*/
17+
class Controller
18+
{
19+
/**
20+
* @SWG\Get(
21+
* path="/foo/{id}",
22+
* @SWG\Parameter(
23+
* name="id",
24+
* in="path",
25+
* type="string",
26+
* required=true
27+
* ),
28+
* @SWG\Response(
29+
* response="200",
30+
* description="Success",
31+
* )
32+
* )
33+
*/
34+
public function noPattern(): void
35+
{
36+
}
37+
38+
/**
39+
* @SWG\Get(
40+
* path="/bar/{id}",
41+
* @SWG\Parameter(
42+
* name="id",
43+
* in="path",
44+
* type="string",
45+
* required=true,
46+
* pattern="^[a-zA-Z0-9]+$"
47+
* ),
48+
* @SWG\Response(
49+
* response="200",
50+
* description="Success",
51+
* )
52+
* )
53+
*/
54+
public function withPattern(): void
55+
{
56+
}
57+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\SeveralClasses;
6+
7+
use Swagger\Annotations as SWG;
8+
9+
/**
10+
* @SWG\Swagger(
11+
* @SWG\Info(
12+
* title="My API",
13+
* version="1.0"
14+
* )
15+
* )
16+
*/
17+
class BarController
18+
{
19+
/**
20+
* @SWG\Get(
21+
* path="/bar",
22+
* @SWG\Response(
23+
* response="200",
24+
* description="Success",
25+
* )
26+
* )
27+
*/
28+
public function __invoke(): void
29+
{
30+
}
31+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\SeveralClasses;
6+
7+
use Swagger\Annotations as SWG;
8+
9+
class FooController
10+
{
11+
/**
12+
* @SWG\Get(
13+
* path="/foo",
14+
* @SWG\Response(
15+
* response="200",
16+
* description="Success",
17+
* )
18+
* )
19+
*/
20+
public function __invoke(): void
21+
{
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\SeveralClasses\SubNamespace;
6+
7+
use Swagger\Annotations as SWG;
8+
9+
class SubController
10+
{
11+
/**
12+
* @SWG\Get(
13+
* path="/sub",
14+
* @SWG\Response(
15+
* response="200",
16+
* description="Success",
17+
* )
18+
* )
19+
*/
20+
public function __invoke(): void
21+
{
22+
}
23+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\SeveralHttpMethods;
6+
7+
use Swagger\Annotations as SWG;
8+
9+
/**
10+
* @SWG\Swagger(
11+
* @SWG\Info(
12+
* title="My API",
13+
* version="1.0"
14+
* )
15+
* )
16+
*/
17+
class Controller
18+
{
19+
/**
20+
* @SWG\Get(
21+
* path="/foobar",
22+
* @SWG\Response(
23+
* response="200",
24+
* description="Success",
25+
* )
26+
* )
27+
*/
28+
public function get(): void
29+
{
30+
}
31+
32+
/**
33+
* @SWG\Put(
34+
* path="/foobar",
35+
* @SWG\Response(
36+
* response="200",
37+
* description="Success",
38+
* )
39+
* )
40+
*/
41+
public function put(): void
42+
{
43+
}
44+
45+
/**
46+
* @SWG\Post(
47+
* path="/foobar",
48+
* @SWG\Response(
49+
* response="200",
50+
* description="Success",
51+
* )
52+
* )
53+
*/
54+
public function post(): void
55+
{
56+
}
57+
58+
/**
59+
* @SWG\Delete(
60+
* path="/foobar",
61+
* @SWG\Response(
62+
* response="200",
63+
* description="Success",
64+
* )
65+
* )
66+
*/
67+
public function delete(): void
68+
{
69+
}
70+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\SeveralRoutesOnOneAction;
6+
7+
use Swagger\Annotations as SWG;
8+
9+
/**
10+
* @SWG\Swagger(
11+
* @SWG\Info(
12+
* title="My API",
13+
* version="1.0"
14+
* )
15+
* )
16+
*/
17+
class Controller
18+
{
19+
/**
20+
* @SWG\Get(
21+
* path="/foobar",
22+
* @SWG\Response(
23+
* response="200",
24+
* description="Success",
25+
* )
26+
* )
27+
*
28+
* @SWG\Post(
29+
* path="/foobar",
30+
* @SWG\Response(
31+
* response="200",
32+
* description="Success",
33+
* )
34+
* )
35+
*
36+
* @SWG\Get(
37+
* path="/foo-bar",
38+
* operationId="my-name",
39+
* @SWG\Response(
40+
* response="200",
41+
* description="Success",
42+
* )
43+
* )
44+
*/
45+
public function __invoke(): void
46+
{
47+
}
48+
}

0 commit comments

Comments
 (0)