diff --git a/packages/openapi-ts-tests/sdks/__snapshots__/opencode/flat/sdk.gen.ts b/packages/openapi-ts-tests/sdks/__snapshots__/opencode/flat/sdk.gen.ts index ee09385a4..281dbfd24 100644 --- a/packages/openapi-ts-tests/sdks/__snapshots__/opencode/flat/sdk.gen.ts +++ b/packages/openapi-ts-tests/sdks/__snapshots__/opencode/flat/sdk.gen.ts @@ -50,7 +50,7 @@ export const sessionCreate = (parameters?: parentID?: string; title?: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "body", key: "parentID" }, { in: "body", key: "title" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "body", key: "parentID" }, { in: "body", key: "title" }] }]); return (options?.client ?? client).post({ url: "/session", ...options, @@ -69,7 +69,7 @@ export const sessionCreate = (parameters?: export const sessionDelete = (parameters: { id: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "path", key: "id" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "id" }] }]); return (options?.client ?? client).delete({ url: "/session/{id}", ...options, @@ -83,7 +83,7 @@ export const sessionDelete = (parameters: export const sessionGet = (parameters: { id: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "path", key: "id" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "id" }] }]); return (options?.client ?? client).get({ url: "/session/{id}", ...options, @@ -98,7 +98,7 @@ export const sessionUpdate = (parameters: id: string; title?: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "path", key: "id" }, { in: "body", key: "title" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "id" }, { in: "body", key: "title" }] }]); return (options?.client ?? client).patch({ url: "/session/{id}", ...options, @@ -117,7 +117,7 @@ export const sessionUpdate = (parameters: export const sessionChildren = (parameters: { id: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "path", key: "id" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "id" }] }]); return (options?.client ?? client).get({ url: "/session/{id}/children", ...options, @@ -134,12 +134,12 @@ export const sessionInit = (parameters: { providerID?: string; modelID?: string; }, options?: Options) => { - const params = buildClientParams([parameters], [ - { in: "path", key: "id" }, - { in: "body", key: "messageID" }, - { in: "body", key: "providerID" }, - { in: "body", key: "modelID" } - ]); + const params = buildClientParams([parameters], [{ args: [ + { in: "path", key: "id" }, + { in: "body", key: "messageID" }, + { in: "body", key: "providerID" }, + { in: "body", key: "modelID" } + ] }]); return (options?.client ?? client).post({ url: "/session/{id}/init", ...options, @@ -158,7 +158,7 @@ export const sessionInit = (parameters: { export const sessionAbort = (parameters: { id: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "path", key: "id" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "id" }] }]); return (options?.client ?? client).post({ url: "/session/{id}/abort", ...options, @@ -172,7 +172,7 @@ export const sessionAbort = (parameters: { export const sessionUnshare = (parameters: { id: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "path", key: "id" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "id" }] }]); return (options?.client ?? client).delete({ url: "/session/{id}/share", ...options, @@ -186,7 +186,7 @@ export const sessionUnshare = (parameters: export const sessionShare = (parameters: { id: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "path", key: "id" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "id" }] }]); return (options?.client ?? client).post({ url: "/session/{id}/share", ...options, @@ -202,11 +202,11 @@ export const sessionSummarize = (parameter providerID?: string; modelID?: string; }, options?: Options) => { - const params = buildClientParams([parameters], [ - { in: "path", key: "id" }, - { in: "body", key: "providerID" }, - { in: "body", key: "modelID" } - ]); + const params = buildClientParams([parameters], [{ args: [ + { in: "path", key: "id" }, + { in: "body", key: "providerID" }, + { in: "body", key: "modelID" } + ] }]); return (options?.client ?? client).post({ url: "/session/{id}/summarize", ...options, @@ -225,7 +225,7 @@ export const sessionSummarize = (parameter export const sessionMessages = (parameters: { id: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "path", key: "id" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "id" }] }]); return (options?.client ?? client).get({ url: "/session/{id}/message", ...options, @@ -254,16 +254,16 @@ export const sessionChat = (parameters: { type: "agent"; } & AgentPartInput)>; }, options?: Options) => { - const params = buildClientParams([parameters], [ - { in: "path", key: "id" }, - { in: "body", key: "messageID" }, - { in: "body", key: "providerID" }, - { in: "body", key: "modelID" }, - { in: "body", key: "agent" }, - { in: "body", key: "system" }, - { in: "body", key: "tools" }, - { in: "body", key: "parts" } - ]); + const params = buildClientParams([parameters], [{ args: [ + { in: "path", key: "id" }, + { in: "body", key: "messageID" }, + { in: "body", key: "providerID" }, + { in: "body", key: "modelID" }, + { in: "body", key: "agent" }, + { in: "body", key: "system" }, + { in: "body", key: "tools" }, + { in: "body", key: "parts" } + ] }]); return (options?.client ?? client).post({ url: "/session/{id}/message", ...options, @@ -283,7 +283,7 @@ export const sessionMessage = (parameters: id: string; messageID: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "path", key: "id" }, { in: "path", key: "messageID" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "id" }, { in: "path", key: "messageID" }] }]); return (options?.client ?? client).get({ url: "/session/{id}/message/{messageID}", ...options, @@ -299,11 +299,11 @@ export const sessionShell = (parameters: { agent?: string; command?: string; }, options?: Options) => { - const params = buildClientParams([parameters], [ - { in: "path", key: "id" }, - { in: "body", key: "agent" }, - { in: "body", key: "command" } - ]); + const params = buildClientParams([parameters], [{ args: [ + { in: "path", key: "id" }, + { in: "body", key: "agent" }, + { in: "body", key: "command" } + ] }]); return (options?.client ?? client).post({ url: "/session/{id}/shell", ...options, @@ -324,11 +324,11 @@ export const sessionRevert = (parameters: messageID?: string; partID?: string; }, options?: Options) => { - const params = buildClientParams([parameters], [ - { in: "path", key: "id" }, - { in: "body", key: "messageID" }, - { in: "body", key: "partID" } - ]); + const params = buildClientParams([parameters], [{ args: [ + { in: "path", key: "id" }, + { in: "body", key: "messageID" }, + { in: "body", key: "partID" } + ] }]); return (options?.client ?? client).post({ url: "/session/{id}/revert", ...options, @@ -347,7 +347,7 @@ export const sessionRevert = (parameters: export const sessionUnrevert = (parameters: { id: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "path", key: "id" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "id" }] }]); return (options?.client ?? client).post({ url: "/session/{id}/unrevert", ...options, @@ -363,11 +363,11 @@ export const postSessionByIdPermissionsByPermissionId = ) => { - const params = buildClientParams([parameters], [ - { in: "path", key: "id" }, - { in: "path", key: "permissionID" }, - { in: "body", key: "response" } - ]); + const params = buildClientParams([parameters], [{ args: [ + { in: "path", key: "id" }, + { in: "path", key: "permissionID" }, + { in: "body", key: "response" } + ] }]); return (options?.client ?? client).post({ url: "/session/{id}/permissions/{permissionID}", ...options, @@ -391,7 +391,7 @@ export const configProviders = (options?: export const findText = (parameters: { pattern: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "query", key: "pattern" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "pattern" }] }]); return (options?.client ?? client).get({ url: "/find", ...options, @@ -405,7 +405,7 @@ export const findText = (parameters: { export const findFiles = (parameters: { query: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "query", key: "query" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "query" }] }]); return (options?.client ?? client).get({ url: "/find/file", ...options, @@ -419,7 +419,7 @@ export const findFiles = (parameters: { export const findSymbols = (parameters: { query: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "query", key: "query" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "query" }] }]); return (options?.client ?? client).get({ url: "/find/symbol", ...options, @@ -433,7 +433,7 @@ export const findSymbols = (parameters: { export const fileRead = (parameters: { path: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "query", key: "path" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "path" }] }]); return (options?.client ?? client).get({ url: "/file", ...options, @@ -457,12 +457,12 @@ export const appLog = (parameters?: { [key: string]: unknown; }; }, options?: Options) => { - const params = buildClientParams([parameters], [ - { in: "body", key: "service" }, - { in: "body", key: "level" }, - { in: "body", key: "message" }, - { in: "body", key: "extra" } - ]); + const params = buildClientParams([parameters], [{ args: [ + { in: "body", key: "service" }, + { in: "body", key: "level" }, + { in: "body", key: "message" }, + { in: "body", key: "extra" } + ] }]); return (options?.client ?? client).post({ url: "/log", ...options, @@ -486,7 +486,7 @@ export const appAgents = (options?: Option export const tuiAppendPrompt = (parameters?: { text?: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "body", key: "text" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "body", key: "text" }] }]); return (options?.client ?? client).post({ url: "/tui/append-prompt", ...options, @@ -535,7 +535,7 @@ export const tuiClearPrompt = (options?: O export const tuiExecuteCommand = (parameters?: { command?: string; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "body", key: "command" }]); + const params = buildClientParams([parameters], [{ args: [{ in: "body", key: "command" }] }]); return (options?.client ?? client).post({ url: "/tui/execute-command", ...options, @@ -556,11 +556,11 @@ export const tuiShowToast = (parameters?: message?: string; variant?: "info" | "success" | "warning" | "error"; }, options?: Options) => { - const params = buildClientParams([parameters], [ - { in: "body", key: "title" }, - { in: "body", key: "message" }, - { in: "body", key: "variant" } - ]); + const params = buildClientParams([parameters], [{ args: [ + { in: "body", key: "title" }, + { in: "body", key: "message" }, + { in: "body", key: "variant" } + ] }]); return (options?.client ?? client).post({ url: "/tui/show-toast", ...options, @@ -580,7 +580,7 @@ export const authSet = (parameters: { id: string; auth?: Auth; }, options?: Options) => { - const params = buildClientParams([parameters], [{ in: "path", key: "id" }, {}]); + const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "id" }, {}] }]); return (options?.client ?? client).put({ url: "/auth/{id}", ...options, diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts index 3193f3cb0..e23477466 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts @@ -544,19 +544,44 @@ export const operationStatements = ({ for (const argName of opParameters.argNames) { args.push($(argName)); } - for (const field of opParameters.fields) { - const shape = $.object(); - if ('in' in field) { - shape.prop('in', $.literal(field.in)); - if (field.key) { - shape.prop('key', $.literal(field.key)); + + // When using flat params, fields need to be wrapped in an args array + if (plugin.config.paramsStructure === 'flat') { + const fieldShapes: Array> = []; + for (const field of opParameters.fields) { + const shape = $.object(); + if ('in' in field) { + shape.prop('in', $.literal(field.in)); + if (field.key) { + shape.prop('key', $.literal(field.key)); + } + if (field.map) { + shape.prop('map', $.literal(field.map)); + } } - if (field.map) { - shape.prop('map', $.literal(field.map)); + fieldShapes.push(shape); + } + // Wrap all fields in an args array for flat params + const argsWrapper = $.object(); + argsWrapper.prop('args', $.array(...fieldShapes)); + config.push(argsWrapper); + } else { + // For grouped params, generate fields as before + for (const field of opParameters.fields) { + const shape = $.object(); + if ('in' in field) { + shape.prop('in', $.literal(field.in)); + if (field.key) { + shape.prop('key', $.literal(field.key)); + } + if (field.map) { + shape.prop('map', $.literal(field.map)); + } } + config.push(shape); } - config.push(shape); } + const symbol = plugin.referenceSymbol({ category: 'external', resource: 'client.buildClientParams',