From b41aee2278a66c76178653e2bee2abe0027ac35d Mon Sep 17 00:00:00 2001 From: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Date: Sun, 25 Jan 2026 20:27:45 +0800 Subject: [PATCH] pass IR.OperationObject as group key builder --- web/plugins/hey-api-orpc/config.ts | 5 +++-- web/plugins/hey-api-orpc/plugin.ts | 2 +- web/plugins/hey-api-orpc/types.d.ts | 11 ++++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/web/plugins/hey-api-orpc/config.ts b/web/plugins/hey-api-orpc/config.ts index 90bfacff26..8987877132 100644 --- a/web/plugins/hey-api-orpc/config.ts +++ b/web/plugins/hey-api-orpc/config.ts @@ -1,3 +1,4 @@ +import type { IR } from '@hey-api/openapi-ts' import type { OrpcPlugin } from './types' import { definePluginConfig } from '@hey-api/openapi-ts' @@ -15,8 +16,8 @@ function toCamelCase(str: string): string { // Default: extract first path segment and convert to camelCase // "/chat-messages/{id}" → "chatMessages" -function defaultGroupKeyBuilder(path: string): string { - const segment = path.split('/').filter(Boolean)[0] || 'common' +function defaultGroupKeyBuilder(operation: IR.OperationObject): string { + const segment = operation.path.split('/').filter(Boolean)[0] || 'common' return toCamelCase(segment) } diff --git a/web/plugins/hey-api-orpc/plugin.ts b/web/plugins/hey-api-orpc/plugin.ts index 76ebbbec97..ef6e629018 100644 --- a/web/plugins/hey-api-orpc/plugin.ts +++ b/web/plugins/hey-api-orpc/plugin.ts @@ -203,7 +203,7 @@ export const handler: OrpcPlugin['Handler'] = ({ plugin }) => { // Group operations by group key const operationsByGroup = new Map() for (const op of operations) { - const groupKey = groupKeyBuilder(op.path as string) + const groupKey = groupKeyBuilder(op) if (!operationsByGroup.has(groupKey)) { operationsByGroup.set(groupKey, []) } diff --git a/web/plugins/hey-api-orpc/types.d.ts b/web/plugins/hey-api-orpc/types.d.ts index 65e479a546..dffb76149a 100644 --- a/web/plugins/hey-api-orpc/types.d.ts +++ b/web/plugins/hey-api-orpc/types.d.ts @@ -1,4 +1,4 @@ -import type { DefinePlugin, Plugin } from '@hey-api/openapi-ts' +import type { DefinePlugin, IR, Plugin } from '@hey-api/openapi-ts' export type UserConfig = Plugin.Name<'orpc'> & Plugin.Hooks & { @@ -23,10 +23,11 @@ export type UserConfig = Plugin.Name<'orpc'> */ defaultTag?: string /** - * Custom function to extract group key from path for router grouping. - * @default (path) => path.split('/').filter(Boolean)[0] || 'common' + * Custom function to extract group key for router grouping. + * Receives the full IR.OperationObject. + * @default extracts first path segment as camelCase */ - groupKeyBuilder?: (path: string) => string + groupKeyBuilder?: (operation: IR.OperationObject) => string /** * Custom function to generate operation key within a group. * @default (operationId, groupKey) => simplified operationId @@ -40,7 +41,7 @@ export type Config = Plugin.Name<'orpc'> exportFromIndex: boolean contractNameBuilder: (operationId: string) => string defaultTag: string - groupKeyBuilder: (path: string) => string + groupKeyBuilder: (operation: IR.OperationObject) => string operationKeyBuilder: (operationId: string, groupKey: string) => string }