File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
tests/Generator/Operation Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -295,10 +295,18 @@ private function setUniqueOperationId(OpenApi $openApi)
295
295
$ names = new UniqueNamesOptionsCollection ;
296
296
297
297
$ this ->foreachOperation ($ openApi , function (Operation $ operation ) use ($ names ) {
298
+ if ($ operation ->operationId ) {
299
+ return ;
300
+ }
301
+
298
302
$ names ->push ($ operation ->getAttribute ('operationId ' )); // @phpstan-ignore argument.type
299
303
});
300
304
301
305
$ this ->foreachOperation ($ openApi , function (Operation $ operation , $ index ) use ($ names ) {
306
+ if ($ operation ->operationId ) {
307
+ return ;
308
+ }
309
+
302
310
$ name = $ operation ->getAttribute ('operationId ' );
303
311
304
312
$ operation ->setOperationId ($ names ->getUniqueName ($ name , function (string $ fallback ) use ($ index ) { // @phpstan-ignore argument.type
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ namespace Dedoc \Scramble \Tests \Generator \Request ;
4
+
3
5
use Dedoc \Scramble \Scramble ;
6
+ use Dedoc \Scramble \Support \Generator \Operation ;
7
+ use Dedoc \Scramble \Support \RouteInfo ;
8
+ use Illuminate \Routing \Controller ;
4
9
use Illuminate \Routing \Route ;
5
10
use Illuminate \Support \Facades \Route as RouteFacade ;
6
11
@@ -86,3 +91,21 @@ public function a(): Illuminate\Http\Resources\Json\JsonResource
86
91
return $ this ->unknown_fn ();
87
92
}
88
93
}
94
+
95
+ it ('documents operation id with manual extension ' , function () {
96
+ Scramble::configure ()->withOperationTransformers (function (Operation $ operation , RouteInfo $ routeInfo ): void {
97
+ $ operation ->setOperationId ('extensionOperationIdDocumentationTest ' );
98
+ });
99
+
100
+ $ openApiDocument = generateForRoute (function () {
101
+ return RouteFacade::get ('api/test ' , [ExtensionOperationIdDocumentationTestController::class, 'a ' ]);
102
+ });
103
+
104
+ expect ($ openApiDocument ['paths ' ]['/test ' ]['get ' ])
105
+ ->toHaveKey ('operationId ' , 'extensionOperationIdDocumentationTest ' );
106
+ });
107
+
108
+ class ExtensionOperationIdDocumentationTestController extends Controller
109
+ {
110
+ public function a () {}
111
+ }
You can’t perform that action at this time.
0 commit comments