-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestController.php
More file actions
149 lines (128 loc) · 6.33 KB
/
Copy pathTestController.php
File metadata and controls
149 lines (128 loc) · 6.33 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?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\DocumentedError;
use Fusonic\ApiDocumentationBundle\Attribute\DocumentedRoute;
use Fusonic\ApiDocumentationBundle\Tests\App\Exception\TestContextAwareException;
use Fusonic\ApiDocumentationBundle\Tests\App\Exception\TestForbiddenException;
use Fusonic\ApiDocumentationBundle\Tests\App\Exception\TestNotFoundException;
use Fusonic\ApiDocumentationBundle\Tests\App\FromRequest;
use Fusonic\ApiDocumentationBundle\Tests\App\Request\TestRequest;
use Fusonic\ApiDocumentationBundle\Tests\App\Request\TestRequestWithIgnoredProperty;
use Fusonic\ApiDocumentationBundle\Tests\App\Request\TestRequestWithIgnoredPropertyOnly;
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;
use Symfony\Component\Routing\Attribute\Route;
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, Response::HTTP_OK);
}
#[DocumentedRoute(path: '/test-status-code/{id}', methods: ['GET'], statusCode: 422)]
public function testStatusCode(#[FromRequest] TestRequest $query): Response
{
return new Response((string) $query->id, Response::HTTP_UNPROCESSABLE_ENTITY);
}
#[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
{
}
#[DocumentedRoute(path: '/test-get-input-with-ignored-property/{id}', methods: ['GET'])]
public function testGetInputWithIgnoredProperty(#[FromRequest] TestRequestWithIgnoredProperty $query): void
{
}
#[DocumentedRoute(path: '/test-get-input-with-ignored-property-only/{id}', methods: ['GET'])]
public function testGetInputWithIgnoredPropertyOnly(#[FromRequest] TestRequestWithIgnoredPropertyOnly $query): void
{
}
#[DocumentedRoute(path: '/test-post-input-with-ignored-property/{id}', methods: ['POST'])]
public function testPostInputWithIgnoredProperty(#[FromRequest] TestRequestWithIgnoredProperty $query): void
{
}
#[DocumentedRoute(path: '/test-post-input-with-ignored-property-only/{id}', methods: ['POST'])]
public function testPostInputWithIgnoredPropertyOnly(#[FromRequest] TestRequestWithIgnoredPropertyOnly $query): void
{
}
#[DocumentedRoute(path: '/test-documented-errors/{id}', methods: ['GET', 'POST'])]
#[DocumentedError(exceptionClass: TestNotFoundException::class, statusCode: 404)]
#[DocumentedError(exceptionClass: TestForbiddenException::class, statusCode: 403, description: 'Access denied')]
#[DocumentedError(exceptionClass: \RuntimeException::class, statusCode: 400, description: 'Bad request')]
#[DocumentedError(exceptionClass: \RuntimeException::class, statusCode: 422, description: 'Validation failed', methods: ['POST'])]
public function testDocumentedErrors(#[FromRequest] TestRequest $query): TestResponse
{
return new TestResponse($query->id);
}
#[Route(path: '/test-documented-errors-plain-route/{id}', methods: ['GET', 'POST'])]
#[DocumentedError(exceptionClass: TestNotFoundException::class, statusCode: 404)]
#[DocumentedError(exceptionClass: TestForbiddenException::class, statusCode: 403, description: 'Access denied')]
#[DocumentedError(exceptionClass: \RuntimeException::class, statusCode: 422, description: 'Validation failed', methods: ['POST'])]
public function testDocumentedErrorsPlainRoute(#[FromRequest] TestRequest $query): TestResponse
{
return new TestResponse($query->id);
}
#[DocumentedRoute(path: '/test-context-aware-error/{id}', methods: ['GET'])]
#[DocumentedError(exceptionClass: TestContextAwareException::class, statusCode: 422, description: 'Context error')]
#[DocumentedError(exceptionClass: TestNotFoundException::class, statusCode: 404)]
public function testContextAwareError(#[FromRequest] TestRequest $query): TestResponse
{
return new TestResponse($query->id);
}
}