Skip to content

Commit

Permalink
Iterate type names
Browse files Browse the repository at this point in the history
  • Loading branch information
anttiviljami committed Sep 10, 2024
1 parent dfbbcff commit 8372257
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "openapicmd",
"description": "OpenAPI Command Line Tool",
"version": "2.6.0-beta.2",
"version": "2.6.0-beta.3",
"author": "Viljami Kuosmanen <[email protected]>",
"bin": {
"openapi": "./bin/run.js"
Expand Down
9 changes: 5 additions & 4 deletions src/typegen/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ function generateBackendOperationMethodTypes(
...operationTypes.map((op) => indent(op, 2)),
'}',
'',
// evil typescript magic for nice typing of openapi-backend operation handlers
'export type OperationContext<operationId extends keyof Operations> = Operations[operationId]["context"];',
'export type OperationResponseBody<operationId extends keyof Operations> = Operations[operationId]["response"];',
'export type TypedApiResponse<ResponseBody, ResponseModel = Record<string, any>> = ResponseModel & { _t?: ResponseBody };',
'export type OperationResponse<operationId extends keyof Operations> = TypedApiResponse<OperationResponseBody<operationId>>;',
'export type OperationHandler<operationId extends keyof Operations, HandlerArgs extends unknown[] = unknown[]> = (...params: [OperationContext<operationId>, ...HandlerArgs]) => Promise<OperationResponse<operationId>>;',
'export type OperationResponse<operationId extends keyof Operations> = Operations[operationId]["response"];',
'export type HandlerResponse<ResponseBody, ResponseModel = Record<string, any>> = ResponseModel & { _t?: ResponseBody };',
'export type OperationHandlerResponse<operationId extends keyof Operations> = HandlerResponse<OperationResponse<operationId>>;',
'export type OperationHandler<operationId extends keyof Operations, HandlerArgs extends unknown[] = unknown[]> = (...params: [OperationContext<operationId>, ...HandlerArgs]) => Promise<OperationHandlerResponse<operationId>>;',
].join('\n');
}

Expand Down

0 comments on commit 8372257

Please sign in to comment.