mirror of
https://github.com/langgenius/dify.git
synced 2026-02-27 13:07:08 +08:00
pass IR.OperationObject as group key builder
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
||||
|
||||
@ -203,7 +203,7 @@ export const handler: OrpcPlugin['Handler'] = ({ plugin }) => {
|
||||
// Group operations by group key
|
||||
const operationsByGroup = new Map<string, IR.OperationObject[]>()
|
||||
for (const op of operations) {
|
||||
const groupKey = groupKeyBuilder(op.path as string)
|
||||
const groupKey = groupKeyBuilder(op)
|
||||
if (!operationsByGroup.has(groupKey)) {
|
||||
operationsByGroup.set(groupKey, [])
|
||||
}
|
||||
|
||||
11
web/plugins/hey-api-orpc/types.d.ts
vendored
11
web/plugins/hey-api-orpc/types.d.ts
vendored
@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user