-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestController.php
95 lines (81 loc) · 3.23 KB
/
TestController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/*
* Copyright (c) Fusonic GmbH. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*/
declare(strict_types=1);
namespace Fusonic\ApiDocumentationBundle\Tests\App\Controller;
use Fusonic\ApiDocumentationBundle\Attribute\DocumentedRoute;
use Fusonic\ApiDocumentationBundle\Tests\App\FromRequest;
use Fusonic\ApiDocumentationBundle\Tests\App\Request\TestRequest;
use Fusonic\ApiDocumentationBundle\Tests\App\Response\TestGenericResponse;
use Fusonic\ApiDocumentationBundle\Tests\App\Response\TestResponse;
use OpenApi\Attributes as OA;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
final class TestController extends AbstractController
{
#[DocumentedRoute(
path: '/test-manual-output/{id}',
methods: ['GET'],
output: TestResponse::class,
)]
public function testManualOutput(#[FromRequest] TestRequest $query): Response
{
return new Response((string) $query->id, 200);
}
#[DocumentedRoute(path: '/test-status-code/{id}', methods: ['GET'], statusCode: 422)]
public function testStatusCode(#[FromRequest] TestRequest $query): Response
{
return new Response((string) $query->id, 422);
}
#[DocumentedRoute(path: '/test-return-type/{id}', methods: ['GET'])]
public function testReturnType(#[FromRequest] TestRequest $query): TestResponse
{
return new TestResponse($query->id);
}
#[DocumentedRoute(path: '/test-builtin-return-type/{id}', methods: ['GET'])]
public function testBuiltinReturnType(#[FromRequest] TestRequest $query): string
{
return (string) $query->id;
}
#[DocumentedRoute(path: '/test-ignored-return-type', methods: ['GET'])]
public function testIgnoredReturnType(): Response
{
return new Response();
}
/**
* @return string[]
*/
#[DocumentedRoute(path: '/annotation-builtin-type-array/{id}', methods: ['GET'])]
public function testAnnotationBuiltinTypeArray(#[FromRequest] TestRequest $query): array
{
return [(string) $query->id];
}
/**
* @return TestResponse[]
*/
#[DocumentedRoute(path: '/test-annotation-custom-return-type/{id}', methods: ['GET'])]
public function testAnnotationCustomReturnTypeArray(#[FromRequest] TestRequest $query): array
{
return [new TestResponse($query->id)];
}
/**
* @return TestGenericResponse<TestResponse>
*/
#[DocumentedRoute(path: '/test-generic-return-type/{id}', methods: ['GET'])]
public function testGenericReturnType(#[FromRequest] TestRequest $query): TestGenericResponse
{
return new TestGenericResponse([new TestResponse($query->id)]);
}
#[DocumentedRoute(path: '/test-combined-attributes/{id}', methods: ['POST'], description: 'Object found')]
#[OA\Response(response: 404, description: 'Object was not found.')]
public function testCombinedAttributes(#[FromRequest] TestRequest $query): TestResponse
{
return new TestResponse($query->id);
}
#[DocumentedRoute(path: '/test-void-return-type', methods: ['GET'])]
public function testVoidReturnType(#[FromRequest] TestRequest $query): void
{
}
}