Skip to content

Commit 598fea4

Browse files
committed
🎉 feat: operationId per possible path
1 parent c3c91bb commit 598fea4

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/openapi.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ export function toOpenAPISchema(
9696

9797
// Start building the operation object
9898
const operation: Partial<OpenAPIV3.OperationObject> = {
99-
...hooks.detail,
100-
operationId: toOperationId(route.method, route.path)
99+
...hooks.detail
101100
}
102101

103102
const parameters: Array<{
@@ -295,26 +294,28 @@ export function toOpenAPISchema(
295294
}
296295

297296
for (let path of getPossiblePath(route.path)) {
297+
const operationId = toOperationId(route.method, route.path)
298+
298299
path = path.replace(/:([^/]+)/g, '{$1}')
299300

300301
if (!paths[path]) paths[path] = {}
301302

302303
const current = paths[path] as any
303304

304305
if (method !== 'all') {
305-
current[method] = operation
306+
current[method] = {
307+
...operation,
308+
operationId
309+
}
306310
continue
307311
}
308312

309313
// Handle 'ALL' method by assigning operation to all standard methods
310-
current.get = operation
311-
current.post = operation
312-
current.put = operation
313-
current.delete = operation
314-
current.patch = operation
315-
current.head = operation
316-
current.options = operation
317-
current.trace = operation
314+
for(const method of ['get', 'post', 'put', 'delete', 'patch', 'head', 'options', 'trace'])
315+
current[method] = {
316+
...operation,
317+
operationId
318+
}
318319
}
319320
}
320321

0 commit comments

Comments
 (0)