Skip to content

Commit 95cf5bd

Browse files
feat: Add openapi documentation for OAuth2SponsorshipTypeApiController
1 parent abbde7c commit 95cf5bd

2 files changed

Lines changed: 195 additions & 15 deletions

File tree

app/Http/Controllers/Apis/Protected/Summit/OAuth2SponsorshipTypeApiController.php

Lines changed: 176 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use models\oauth2\IResourceServerContext;
1919
use models\summit\ISummitRepository;
2020
use ModelSerializers\SerializerRegistry;
21+
use OpenApi\Attributes as OA;
22+
use Symfony\Component\HttpFoundation\Response;
23+
2124
/**
2225
* Class OAuth2SponsorshipTypeApiController
2326
* @package App\Http\Controllers
@@ -101,9 +104,108 @@ protected function getSummitRepository(): ISummitRepository
101104
}
102105

103106
use GetAndValidateJsonPayload;
104-
/**
105-
* @return \Illuminate\Http\JsonResponse|mixed
106-
*/
107+
108+
#[OA\Get(
109+
path: "/api/v1/sponsorship-types",
110+
summary: "Get all sponsorship types",
111+
security: [["bearer_token" => []]],
112+
tags: ["SponsorshipTypes"],
113+
parameters: [
114+
new OA\Parameter(name: "page", description: "Page number", in: "query", required: false, schema: new OA\Schema(type: "integer", default: 1)),
115+
new OA\Parameter(name: "per_page", description: "Items per page", in: "query", required: false, schema: new OA\Schema(type: "integer", default: 10)),
116+
new OA\Parameter(name: "filter", description: "Filter query (name==value, label=@value, size==value)", in: "query", required: false, schema: new OA\Schema(type: "string")),
117+
new OA\Parameter(name: "order", description: "Order by (+id, -name, +order, +label, +size)", in: "query", required: false, schema: new OA\Schema(type: "string")),
118+
],
119+
responses: [
120+
new OA\Response(
121+
response: Response::HTTP_OK,
122+
description: "OK",
123+
content: new OA\JsonContent(
124+
allOf: [
125+
new OA\Schema(ref: "#/components/schemas/PaginateDataSchemaResponse"),
126+
new OA\Schema(
127+
type: "object",
128+
properties: [
129+
new OA\Property(
130+
property: "data",
131+
type: "array",
132+
items: new OA\Items(ref: "#/components/schemas/SponsorshipType")
133+
)
134+
]
135+
)
136+
]
137+
)
138+
),
139+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
140+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
141+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
142+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
143+
]
144+
)]
145+
public function getAll()
146+
{
147+
return $this->_getAll(
148+
function(){
149+
return [
150+
'name' => ['==', '=@'],
151+
'label' => ['==', '=@'],
152+
'size' => ['==', '=@'],
153+
];
154+
},
155+
function(){
156+
return [
157+
'name' => 'sometimes|required|string',
158+
'label' => 'sometimes|required|string',
159+
'size' => 'sometimes|required|string',
160+
];
161+
},
162+
function(){
163+
return [
164+
'id',
165+
'name',
166+
'order',
167+
'label',
168+
'size',
169+
];
170+
},
171+
function($filter){
172+
return $filter;
173+
},
174+
function(){
175+
return SerializerRegistry::SerializerType_Public;
176+
}
177+
);
178+
}
179+
180+
#[OA\Post(
181+
path: "/api/v1/sponsorship-types",
182+
summary: "Add a new sponsorship type",
183+
security: [["bearer_token" => []]],
184+
tags: ["SponsorshipTypes"],
185+
requestBody: new OA\RequestBody(
186+
required: true,
187+
content: new OA\JsonContent(
188+
required: ["name", "label", "size"],
189+
properties: [
190+
new OA\Property(property: "name", type: "string", description: "Sponsorship type name"),
191+
new OA\Property(property: "label", type: "string", description: "Display label"),
192+
new OA\Property(property: "size", type: "string", description: "Size category", enum: ["Small", "Medium", "Large", "Big"]),
193+
]
194+
)
195+
),
196+
responses: [
197+
new OA\Response(
198+
response: Response::HTTP_CREATED,
199+
description: "Created",
200+
content: new OA\JsonContent(ref: "#/components/schemas/SponsorshipType")
201+
),
202+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
203+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
204+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
205+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
206+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
207+
]
208+
)]
107209
public function add()
108210
{
109211
return $this->processRequest(function(){
@@ -124,10 +226,27 @@ public function add()
124226
});
125227
}
126228

127-
/**
128-
* @param $id
129-
* @return \Illuminate\Http\JsonResponse|mixed
130-
*/
229+
#[OA\Get(
230+
path: "/api/v1/sponsorship-types/{id}",
231+
summary: "Get a sponsorship type by id",
232+
security: [["bearer_token" => []]],
233+
tags: ["SponsorshipTypes"],
234+
parameters: [
235+
new OA\Parameter(name: "id", description: "Sponsorship Type ID", in: "path", required: true, schema: new OA\Schema(type: "integer")),
236+
],
237+
responses: [
238+
new OA\Response(
239+
response: Response::HTTP_OK,
240+
description: "OK",
241+
content: new OA\JsonContent(ref: "#/components/schemas/SponsorshipType")
242+
),
243+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
244+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
245+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
246+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "not found"),
247+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
248+
]
249+
)]
131250
public function get($id)
132251
{
133252
return $this->processRequest(function() use($id){
@@ -144,10 +263,39 @@ public function get($id)
144263
});
145264
}
146265

147-
/**
148-
* @param $id
149-
* @return \Illuminate\Http\JsonResponse|mixed
150-
*/
266+
#[OA\Put(
267+
path: "/api/v1/sponsorship-types/{id}",
268+
summary: "Update a sponsorship type",
269+
security: [["bearer_token" => []]],
270+
tags: ["SponsorshipTypes"],
271+
parameters: [
272+
new OA\Parameter(name: "id", description: "Sponsorship Type ID", in: "path", required: true, schema: new OA\Schema(type: "integer")),
273+
],
274+
requestBody: new OA\RequestBody(
275+
required: true,
276+
content: new OA\JsonContent(
277+
properties: [
278+
new OA\Property(property: "name", type: "string", description: "Sponsorship type name"),
279+
new OA\Property(property: "label", type: "string", description: "Display label"),
280+
new OA\Property(property: "size", type: "string", description: "Size category", enum: ["Small", "Medium", "Large", "Big"]),
281+
new OA\Property(property: "order", type: "integer", description: "Display order (minimum: 1)", minimum: 1),
282+
]
283+
)
284+
),
285+
responses: [
286+
new OA\Response(
287+
response: Response::HTTP_OK,
288+
description: "OK",
289+
content: new OA\JsonContent(ref: "#/components/schemas/SponsorshipType")
290+
),
291+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
292+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
293+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
294+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "not found"),
295+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
296+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
297+
]
298+
)]
151299
public function update($id)
152300
{
153301
return $this->processRequest(function() use($id){
@@ -168,10 +316,23 @@ public function update($id)
168316
});
169317
}
170318

171-
/**
172-
* @param $id
173-
* @return \Illuminate\Http\JsonResponse|mixed
174-
*/
319+
#[OA\Delete(
320+
path: "/api/v1/sponsorship-types/{id}",
321+
summary: "Delete a sponsorship type",
322+
security: [["bearer_token" => []]],
323+
tags: ["SponsorshipTypes"],
324+
parameters: [
325+
new OA\Parameter(name: "id", description: "Sponsorship Type ID", in: "path", required: true, schema: new OA\Schema(type: "integer")),
326+
],
327+
responses: [
328+
new OA\Response(response: Response::HTTP_NO_CONTENT, description: "No Content"),
329+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request"),
330+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized"),
331+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden"),
332+
new OA\Response(response: Response::HTTP_NOT_FOUND, description: "not found"),
333+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
334+
]
335+
)]
175336
public function delete($id)
176337
{
177338
return $this->processRequest(function() use($id){
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
namespace App\Swagger\schemas;
3+
4+
use OpenApi\Attributes as OA;
5+
6+
#[OA\Schema(
7+
schema: 'SponsorshipType',
8+
type: 'object',
9+
properties: [
10+
new OA\Property(property: 'id', type: 'integer'),
11+
new OA\Property(property: 'created', type: 'integer'),
12+
new OA\Property(property: 'last_edited', type: 'integer'),
13+
new OA\Property(property: 'name', type: 'string'),
14+
new OA\Property(property: 'label', type: 'string'),
15+
new OA\Property(property: 'order', type: 'integer'),
16+
new OA\Property(property: 'size', type: 'string', description: 'Sponsorship size category'),
17+
]
18+
)]
19+
class SponsorshipTypeSchemas {}

0 commit comments

Comments
 (0)