Skip to content

Commit c5dffc3

Browse files
feat: Add OpenAPI documentation to "getAllUserStories" method
- Add controller's response to OpenAPI schema
1 parent a256c35 commit c5dffc3

2 files changed

Lines changed: 132 additions & 1 deletion

File tree

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

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
**/
1414

1515
use App\Models\Foundation\Main\Repositories\IUserStoryRepository;
16+
use Illuminate\Http\Response;
1617
use models\oauth2\IResourceServerContext;
1718
use models\utils\IEntity;
1819
use ModelSerializers\SerializerRegistry;
20+
use OpenApi\Attributes as OA;
1921

2022
/**
2123
* Class OAuth2UserStoriesApiController
@@ -41,6 +43,73 @@ public function __construct
4143
$this->repository = $repository;
4244
}
4345

46+
// OpenAPI Documentation
47+
48+
#[OA\Get(
49+
path: '/api/public/v1/user-stories',
50+
summary: 'Get all user stories',
51+
description: 'Retrieves a paginated list of user stories showcasing real-world use cases and success stories from the OpenStack community. User stories highlight how organizations use OpenStack in production. This is a public endpoint that can return different data based on authentication (more details for authenticated users).',
52+
tags: ['User Stories'],
53+
parameters: [
54+
new OA\Parameter(
55+
name: 'page',
56+
in: 'query',
57+
required: false,
58+
description: 'Page number for pagination',
59+
schema: new OA\Schema(type: 'integer', example: 1)
60+
),
61+
new OA\Parameter(
62+
name: 'per_page',
63+
in: 'query',
64+
required: false,
65+
description: 'Items per page',
66+
schema: new OA\Schema(type: 'integer', example: 10, maximum: 100)
67+
),
68+
new OA\Parameter(
69+
name: 'filter[]',
70+
in: 'query',
71+
required: false,
72+
description: 'Filter expressions. Format: field<op>value. Available field: name (=@, ==, @@). Operators: == (equals), =@ (starts with), @@ (contains)',
73+
style: 'form',
74+
explode: true,
75+
schema: new OA\Schema(
76+
type: 'array',
77+
items: new OA\Items(type: 'string', example: 'name@@cloud')
78+
)
79+
),
80+
new OA\Parameter(
81+
name: 'order',
82+
in: 'query',
83+
required: false,
84+
description: 'Order by field(s). Available fields: name, id. Use "-" prefix for descending order.',
85+
schema: new OA\Schema(type: 'string', example: 'name')
86+
),
87+
new OA\Parameter(
88+
name: 'expand',
89+
in: 'query',
90+
required: false,
91+
description: 'Expand relationships. Available: organization, industry, location, image, tags',
92+
schema: new OA\Schema(type: 'string', example: 'organization,tags')
93+
),
94+
new OA\Parameter(
95+
name: 'relations',
96+
in: 'query',
97+
required: false,
98+
description: 'Relations to load. Available: tags',
99+
schema: new OA\Schema(type: 'string', example: 'tags')
100+
),
101+
],
102+
responses: [
103+
new OA\Response(
104+
response: 200,
105+
description: 'User stories retrieved successfully',
106+
content: new OA\JsonContent(ref: '#/components/schemas/PaginatedUserStoriesResponse')
107+
),
108+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
109+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error"),
110+
]
111+
)]
112+
44113
/**
45114
* @return mixed
46115
*/
@@ -78,4 +147,4 @@ protected function getEntitySerializerType(): string
78147
return !is_null($currentUser) ? SerializerRegistry::SerializerType_Private :
79148
SerializerRegistry::SerializerType_Public;
80149
}
81-
}
150+
}

app/Swagger/schemas.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,65 @@ class RSVPUpdateRequestSchema_{
376376
]
377377
)]
378378
class RSVPAdminAddRequestSchema {}
379+
380+
// Legal Documents
381+
382+
#[OA\Schema(
383+
schema: 'LegalDocument',
384+
type: 'object',
385+
properties: [
386+
new OA\Property(property: 'id', type: 'integer', example: 1),
387+
new OA\Property(property: 'title', type: 'string', example: 'Privacy Policy'),
388+
new OA\Property(property: 'slug', type: 'string', example: 'privacy-policy'),
389+
new OA\Property(property: 'content', type: 'string', example: 'This privacy policy describes how we handle your data...'),
390+
]
391+
)]
392+
class LegalDocumentSchema {}
393+
394+
// User Stories
395+
396+
#[OA\Schema(
397+
schema: 'UserStory',
398+
type: 'object',
399+
properties: [
400+
new OA\Property(property: 'id', type: 'integer', example: 1),
401+
new OA\Property(property: 'created', type: 'integer', example: 1633024800, description: 'Unix timestamp when created'),
402+
new OA\Property(property: 'last_edited', type: 'integer', example: 1633111200, description: 'Unix timestamp when last updated'),
403+
new OA\Property(property: 'name', type: 'string', example: 'Large Scale Cloud Infrastructure'),
404+
new OA\Property(property: 'description', type: 'string', example: 'Full description of how this organization uses OpenStack...'),
405+
new OA\Property(property: 'short_description', type: 'string', example: 'Brief overview of the use case'),
406+
new OA\Property(property: 'link', type: 'string', nullable: true, example: 'https://example.com/case-study'),
407+
new OA\Property(property: 'active', type: 'boolean', example: true),
408+
new OA\Property(property: 'is_million_core_club', type: 'boolean', example: false, description: 'Whether this is a million core club member'),
409+
new OA\Property(property: 'organization', type: 'Organization'),
410+
new OA\Property(property: 'industry', type: 'Industry'),
411+
new OA\Property(property: 'location', type: 'Location'),
412+
new OA\Property(property: 'image', type: 'Image'),
413+
new OA\Property(
414+
property: 'tags',
415+
type: 'array',
416+
description: 'Array of tag IDs (use expand=tags for full details)',
417+
items: new OA\Items(type: 'integer'),
418+
example: [1, 2, 3]
419+
),
420+
]
421+
)]
422+
class UserStorySchema {}
423+
424+
#[OA\Schema(
425+
schema: 'PaginatedUserStoriesResponse',
426+
allOf: [
427+
new OA\Schema(ref: '#/components/schemas/PaginateDataSchemaResponse'),
428+
new OA\Schema(
429+
type: 'object',
430+
properties: [
431+
new OA\Property(
432+
property: 'data',
433+
type: 'array',
434+
items: new OA\Items(ref: '#/components/schemas/UserStory')
435+
)
436+
]
437+
)
438+
]
439+
)]
440+
class PaginatedUserStoriesResponseSchema {}

0 commit comments

Comments
 (0)