Skip to content

Commit e912c81

Browse files
Feature | Extend Swagger Coverage for controller ConsultantsApiController (#364)
* feat: Add OpenAPI documentation to "getAll" method * chore: Add controller's response OpenAPI schema * chore: move schema to independent file for Marketplace schemas * fix: Change "namespace" word positioning
1 parent ac9cc6a commit e912c81

File tree

2 files changed

+99
-3
lines changed

2 files changed

+99
-3
lines changed

app/Http/Controllers/Apis/Marketplace/ConsultantsApiController.php

Lines changed: 65 additions & 2 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 2017 OpenStack Foundation
47
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,7 +15,9 @@
1215
* limitations under the License.
1316
**/
1417
use App\Models\Foundation\Marketplace\IConsultantRepository;
18+
use Illuminate\Http\Response;
1519
use models\oauth2\IResourceServerContext;
20+
use OpenApi\Attributes as OA;
1621

1722
/**
1823
* Class ConsultantsApiController
@@ -30,8 +35,66 @@ public function __construct(IConsultantRepository $repository, IResourceServerCo
3035
parent::__construct($repository, $resource_server_context);
3136
}
3237

38+
#[OA\Get(
39+
path: "/api/public/v1/marketplace/consultants",
40+
description: "Get all marketplace consultants and consulting services",
41+
summary: 'Get all consultants',
42+
operationId: 'getAllConsultants',
43+
tags: ['Consultants'],
44+
parameters: [
45+
new OA\Parameter(
46+
name: 'filter[]',
47+
in: 'query',
48+
required: false,
49+
description: 'Filter expressions in the format field<op>value. Available fields: name, company. Operators: =@, ==, @@.',
50+
style: 'form',
51+
explode: true,
52+
schema: new OA\Schema(
53+
type: 'array',
54+
items: new OA\Items(type: 'string', example: 'name@@consulting')
55+
)
56+
),
57+
new OA\Parameter(
58+
name: 'order',
59+
in: 'query',
60+
required: false,
61+
description: 'Order by field(s)',
62+
schema: new OA\Schema(type: 'string', example: 'name,-id')
63+
),
64+
new OA\Parameter(
65+
name: 'expand',
66+
in: 'query',
67+
required: false,
68+
description: 'Comma-separated list of related resources to include. Available relations: company, type, offices, clients, spoken_languages, configuration_management_expertise, expertise_areas, services_offered, supported_regions',
69+
schema: new OA\Schema(type: 'string', example: 'company,offices')
70+
),
71+
new OA\Parameter(
72+
name: 'relations',
73+
in: 'query',
74+
required: false,
75+
description: 'Relations to load eagerly',
76+
schema: new OA\Schema(type: 'string', example: 'company,offices')
77+
),
78+
new OA\Parameter(
79+
name: 'fields',
80+
in: 'query',
81+
required: false,
82+
description: 'Comma-separated list of fields to return',
83+
schema: new OA\Schema(type: 'string', example: 'id,name,company.name')
84+
),
85+
],
86+
responses: [
87+
new OA\Response(
88+
response: 200,
89+
description: 'Success - Returns paginated list of consultants',
90+
content: new OA\JsonContent(ref: '#/components/schemas/PaginatedConsultantsResponse')
91+
),
92+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error"),
93+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error")
94+
]
95+
)]
3396
public function getAll()
3497
{
3598
return parent::getAll();
3699
}
37-
}
100+
}

app/Swagger/MarketplaceSchemas.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,37 @@
44

55
use OpenApi\Attributes as OA;
66

7-
//
7+
8+
#[OA\Schema(
9+
schema: 'ConsultantsResponse',
10+
type: 'object',
11+
properties: [
12+
'id' => new OA\Property(property: 'id', type: 'integer', example: 1),
13+
'class_name' => new OA\Property(property: 'class_name', type: 'string', example: 'Consultant'),
14+
'name' => new OA\Property(property: 'name', type: 'string', example: 'OpenStack Consulting Services'),
15+
'overview' => new OA\Property(property: 'overview', type: 'string', example: 'Professional OpenStack consulting and support services'),
16+
'call_2_action_url' => new OA\Property(property: 'call_2_action_url', type: 'string', example: 'https://example.com/contact'),
17+
'slug' => new OA\Property(property: 'slug', type: 'string', example: 'openstack-consulting'),
18+
'company_id' => new OA\Property(property: 'company_id', type: 'integer', example: 1),
19+
'type_id' => new OA\Property(property: 'type_id', type: 'integer', example: 1)
20+
]
21+
)]
22+
class ConsultantsResponseSchema {}
23+
24+
#[OA\Schema(
25+
schema: 'PaginatedConsultantsResponse',
26+
allOf: [
27+
new OA\Schema(ref: '#/components/schemas/PaginateDataSchemaResponse'),
28+
new OA\Schema(
29+
type: 'object',
30+
properties: [
31+
new OA\Property(
32+
property: 'data',
33+
type: 'array',
34+
items: new OA\Items(ref: '#/components/schemas/ConsultantsResponse')
35+
)
36+
]
37+
)
38+
]
39+
)]
40+
class PaginatedConsultantsResponseSchema {}

0 commit comments

Comments
 (0)