Skip to content

Commit 25001af

Browse files
feat: Add OpenAPI documentation to "getAll" and "add" methods
- Add controller's response to OpenAPI schema
1 parent abbde7c commit 25001af

2 files changed

Lines changed: 136 additions & 3 deletions

File tree

app/Http/Controllers/Apis/Protected/Main/OAuth2OrganizationsApiController.php

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
<?php namespace App\Http\Controllers;
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
25
/**
36
* Copyright 2018 OpenStack Foundation
47
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,11 +15,14 @@
1215
* limitations under the License.
1316
**/
1417

18+
use App\Security\SummitScopes;
1519
use App\Services\Model\IOrganizationService;
20+
use Illuminate\Http\Response;
1621
use models\main\IOrganizationRepository;
1722
use models\oauth2\IResourceServerContext;
1823
use models\utils\IEntity;
1924
use ModelSerializers\SerializerRegistry;
25+
use OpenApi\Attributes as OA;
2026

2127
/**
2228
* Class OAuth2OrganizationsApiController
@@ -30,6 +36,31 @@ final class OAuth2OrganizationsApiController extends OAuth2ProtectedController
3036
private $service;
3137

3238
use ParametrizedGetAll;
39+
use AddEntity;
40+
41+
#[OA\Post(
42+
path: '/api/v1/organizations',
43+
summary: 'Creates a new organization',
44+
security: [['oauth2_security_scope' => [SummitScopes::ReadAllSummitData, SummitScopes::WriteSummitData]]],
45+
tags: ['organizations'],
46+
requestBody: new OA\RequestBody(
47+
required: true,
48+
content: new OA\JsonContent(ref: '#/components/schemas/OrganizationCreateRequest')
49+
),
50+
responses: [
51+
new OA\Response(
52+
response: 201,
53+
description: 'Organization created successfully',
54+
content: new OA\JsonContent(ref: '#/components/schemas/Organization')
55+
),
56+
new OA\Response(response: 400, ref: '#/components/responses/400'),
57+
new OA\Response(response: 401, ref: '#/components/responses/401'),
58+
new OA\Response(response: 403, ref: '#/components/responses/403'),
59+
new OA\Response(response: 412, ref: '#/components/responses/412'),
60+
new OA\Response(response: 422, ref: '#/components/responses/422'),
61+
new OA\Response(response: 500, ref: '#/components/responses/500'),
62+
]
63+
)]
3364

3465
/**
3566
* OAuth2OrganizationsApiController constructor.
@@ -49,6 +80,70 @@ public function __construct
4980
$this->service = $service;
5081
}
5182

83+
#[OA\Get(
84+
path: "/api/v1/organizations",
85+
description: "Get all organizations with filtering and pagination. Organizations represent companies, foundations, or entities in the system. Requires OAuth2 authentication with appropriate scope.",
86+
summary: 'Get all organizations',
87+
operationId: 'getAllOrganizations',
88+
tags: ['Organizations'],
89+
security: [['summit_rsvp_oauth2' => [
90+
SummitScopes::ReadAllSummitData,
91+
]]],
92+
parameters: [
93+
new OA\Parameter(
94+
name: 'access_token',
95+
in: 'query',
96+
required: false,
97+
description: 'OAuth2 access token (alternative to Authorization: Bearer)',
98+
schema: new OA\Schema(type: 'string', example: 'eyJhbGciOi...')
99+
),
100+
new OA\Parameter(
101+
name: 'page',
102+
in: 'query',
103+
required: false,
104+
description: 'Page number for pagination',
105+
schema: new OA\Schema(type: 'integer', example: 1)
106+
),
107+
new OA\Parameter(
108+
name: 'per_page',
109+
in: 'query',
110+
required: false,
111+
description: 'Items per page',
112+
schema: new OA\Schema(type: 'integer', example: 10, maximum: 100)
113+
),
114+
new OA\Parameter(
115+
name: 'filter[]',
116+
in: 'query',
117+
required: false,
118+
description: 'Filter expressions. Format: field<op>value. Available field: name (=@, ==, @@). Operators: == (equals), =@ (starts with), @@ (contains)',
119+
style: 'form',
120+
explode: true,
121+
schema: new OA\Schema(
122+
type: 'array',
123+
items: new OA\Items(type: 'string', example: 'name@@OpenStack')
124+
)
125+
),
126+
new OA\Parameter(
127+
name: 'order',
128+
in: 'query',
129+
required: false,
130+
description: 'Order by field(s). Available fields: name, id. Use "-" prefix for descending order.',
131+
schema: new OA\Schema(type: 'string', example: 'name')
132+
),
133+
],
134+
responses: [
135+
new OA\Response(
136+
response: 200,
137+
description: 'Success - Returns paginated list of organizations',
138+
content: new OA\JsonContent(ref: '#/components/schemas/PaginatedOrganizationsResponse')
139+
),
140+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request - Invalid parameters"),
141+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized - Invalid or missing access token"),
142+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden - Insufficient permissions"),
143+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
144+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error")
145+
]
146+
)]
52147
public function getAll()
53148
{
54149
return $this->_getAll(
@@ -77,7 +172,6 @@ function () {
77172
);
78173
}
79174

80-
use AddEntity;
81175

82176
/**
83177
* @inheritDoc
@@ -96,4 +190,4 @@ protected function addEntity(array $payload): IEntity
96190
{
97191
return $this->service->addOrganization($payload);
98192
}
99-
}
193+
}

app/Swagger/schemas.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,42 @@ class RSVPUpdateRequestSchema_{
351351
]
352352
)]
353353
class RSVPAdminAddRequestSchema {}
354+
355+
#[OA\Schema(
356+
schema: 'Organization',
357+
type: 'object',
358+
properties: [
359+
new OA\Property(property: 'id', type: 'integer', example: 1),
360+
new OA\Property(property: 'created', type: 'integer', format: 'int64', example: 1633024800),
361+
new OA\Property(property: 'last_edited', type: 'integer', format: 'int64', example: 1633024800),
362+
new OA\Property(property: 'name', type: 'string', example: 'OpenStack Foundation'),
363+
]
364+
)]
365+
class OrganizationSchema {}
366+
367+
#[OA\Schema(
368+
schema: 'PaginatedOrganizationsResponse',
369+
allOf: [
370+
new OA\Schema(ref: '#/components/schemas/PaginateDataSchemaResponse'),
371+
new OA\Schema(
372+
properties: [
373+
new OA\Property(
374+
property: 'data',
375+
type: 'array',
376+
items: new OA\Items(ref: '#/components/schemas/Organization')
377+
)
378+
]
379+
)
380+
]
381+
)]
382+
class PaginatedOrganizationsResponseSchema {}
383+
384+
#[OA\Schema(
385+
schema: 'OrganizationCreateRequest',
386+
required: ['name'],
387+
type: 'object',
388+
properties: [
389+
new OA\Property(property: 'name', type: 'string', maxLength: 255, example: 'OpenStack Foundation'),
390+
]
391+
)]
392+
class OrganizationCreateRequestSchema {}

0 commit comments

Comments
 (0)