Skip to content

Commit 569f73e

Browse files
committed
added operationId
Signed-off-by: bidi <bidi@apidemia.com>
1 parent 5401882 commit 569f73e

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎docs/book/v2/component/module.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,10 @@ Location: `src/<ModuleName>/src/RoutesDelegator.php`
300300
> This component is created only when a project type is API.
301301
302302
It is generated automatically and contains the basic description of the API endpoints found in this Module.
303+
Each endpoint gets an `operationId`, a name unique across the API, built from its handler class name without the `Handler` suffix and with a lowercase first letter (for example `getBookCollection` for `GetBookCollectionHandler`).
303304
Once you extend the entities with additional fields, you will need to update the OpenAPI file manually.
304305

305-
Location: `src/<ModuleName>/src/RoutesDelegator.php`
306+
Location: `src/<ModuleName>/src/OpenAPI.php`
306307

307308
### ConfigProvider
308309

‎src/Type/OpenApi.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Dot\Maker\IO\Output;
1414

1515
use function implode;
16+
use function lcfirst;
17+
use function preg_replace;
1618
use function sprintf;
1719

1820
use const PHP_EOL;
@@ -84,6 +86,7 @@ public function render(
8486
*/
8587
#[OA\Delete(
8688
path: '/{$entity->toKebabCase()}/{id}',
89+
operationId: '{$this->operationId($apiDeleteResourceHandler)}',
8790
description: 'Authenticated (super)admin deletes resource of type {$entity->getClassName()}, identified by its ID',
8891
summary: 'Admin deletes a resource of type {$entity->getClassName()}',
8992
security: [['AuthToken' => []]],
@@ -122,6 +125,7 @@ public function render(
122125
*/
123126
#[OA\Get(
124127
path: '/{$entity->toKebabCase()}/{id}',
128+
operationId: '{$this->operationId($apiGetResourceHandler)}',
125129
description: 'Authenticated (super)admin fetches a resource of type {$entity->getClassName()}, identified by its ID',
126130
summary: 'Admin fetches a resource of type {$entity->getClassName()}',
127131
security: [['AuthToken' => []]],
@@ -163,6 +167,7 @@ public function render(
163167
*/
164168
#[OA\Get(
165169
path: '/{$entity->toKebabCase()}',
170+
operationId: '{$this->operationId($apiGetCollectionHandler)}',
166171
description: 'Authenticated (super)admin fetches a list of {$entity->toPlural()}',
167172
summary: 'Admin lists {$entity->toPlural()}',
168173
security: [['AuthToken' => []]],
@@ -238,6 +243,7 @@ public function render(
238243
*/
239244
#[OA\Patch(
240245
path: '/{$entity->toKebabCase()}/{id}',
246+
operationId: '{$this->operationId($apiPatchResourceHandler)}',
241247
description: 'Authenticated (super)admin updates an existing {$entity->getClassName()}',
242248
summary: 'Admin updates an existing {$entity->getClassName()}',
243249
security: [['AuthToken' => []]],
@@ -296,6 +302,7 @@ public function render(
296302
*/
297303
#[OA\Post(
298304
path: '/{$entity->toKebabCase()}',
305+
operationId: '{$this->operationId($apiPostResourceHandler)}',
299306
description: 'Authenticated (super)admin creates a new {$entity->getClassName()}',
300307
summary: 'Admin creates a new {$entity->getClassName()}',
301308
security: [['AuthToken' => []]],
@@ -346,6 +353,7 @@ public function render(
346353
*/
347354
#[OA\Put(
348355
path: '/{$entity->toKebabCase()}/{id}',
356+
operationId: '{$this->operationId($apiPutResourceHandler)}',
349357
description: 'Authenticated (super)admin replaces an existing {$entity->getClassName()}',
350358
summary: 'Admin updates an existing {$entity->getClassName()}',
351359
security: [['AuthToken' => []]],
@@ -460,4 +468,9 @@ public function render(
460468

461469
return $class->render();
462470
}
471+
472+
private function operationId(File $handler): string
473+
{
474+
return lcfirst((string) preg_replace('/Handler$/', '', $handler->getComponent()->getClassName()));
475+
}
463476
}

‎test/Type/OpenApiTest.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ private function dataProviderRenderedOpenApi(): string
169169
*/
170170
#[OA\Delete(
171171
path: '/module-name/{id}',
172+
operationId: 'deleteModuleNameResource',
172173
description: 'Authenticated (super)admin deletes resource of type ModuleName, identified by its ID',
173174
summary: 'Admin deletes a resource of type ModuleName',
174175
security: [['AuthToken' => []]],
@@ -199,6 +200,7 @@ private function dataProviderRenderedOpenApi(): string
199200
*/
200201
#[OA\Get(
201202
path: '/module-name/{id}',
203+
operationId: 'getModuleNameResource',
202204
description: 'Authenticated (super)admin fetches a resource of type ModuleName, identified by its ID',
203205
summary: 'Admin fetches a resource of type ModuleName',
204206
security: [['AuthToken' => []]],
@@ -230,6 +232,7 @@ private function dataProviderRenderedOpenApi(): string
230232
*/
231233
#[OA\Get(
232234
path: '/module-name',
235+
operationId: 'getModuleNameCollection',
233236
description: 'Authenticated (super)admin fetches a list of ModuleNames',
234237
summary: 'Admin lists ModuleNames',
235238
security: [['AuthToken' => []]],
@@ -297,6 +300,7 @@ private function dataProviderRenderedOpenApi(): string
297300
*/
298301
#[OA\Patch(
299302
path: '/module-name/{id}',
303+
operationId: 'patchModuleNameResource',
300304
description: 'Authenticated (super)admin updates an existing ModuleName',
301305
summary: 'Admin updates an existing ModuleName',
302306
security: [['AuthToken' => []]],
@@ -347,6 +351,7 @@ private function dataProviderRenderedOpenApi(): string
347351
*/
348352
#[OA\Post(
349353
path: '/module-name',
354+
operationId: 'postModuleNameResource',
350355
description: 'Authenticated (super)admin creates a new ModuleName',
351356
summary: 'Admin creates a new ModuleName',
352357
security: [['AuthToken' => []]],
@@ -389,6 +394,7 @@ private function dataProviderRenderedOpenApi(): string
389394
*/
390395
#[OA\Put(
391396
path: '/module-name/{id}',
397+
operationId: 'putModuleNameResource',
392398
description: 'Authenticated (super)admin replaces an existing ModuleName',
393399
summary: 'Admin updates an existing ModuleName',
394400
security: [['AuthToken' => []]],

0 commit comments

Comments
 (0)