fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #3255 from jsjames/fix-body-param

handle case where paramsStructure = 'flat' and body is an param.

authored by

Lubos and committed by
GitHub
7a04b277 f9303ff4

+44 -23
+5
.changeset/stale-parts-warn.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + **plugin(@hey-api/sdk)**: correctly map body keys in flat mode
+6 -6
dev/openapi-ts.config.ts
··· 48 48 path: path.resolve( 49 49 getSpecsPath(), 50 50 // '2.0.x', 51 - '3.0.x', 52 - // '3.1.x', 51 + // '3.0.x', 52 + '3.1.x', 53 53 // 'circular.yaml', 54 54 // 'dutchie.json', 55 55 // 'enum-names-values.yaml', ··· 58 58 // 'invalid', 59 59 // 'object-property-names.yaml', 60 60 // 'openai.yaml', 61 - // 'opencode.yaml', 61 + 'opencode.yaml', 62 62 // 'pagination-ref.yaml', 63 - 'ref-deep.yaml', 63 + // 'ref-deep.yaml', 64 64 // 'schema-const.yaml', 65 65 // 'sdk-instance.yaml', 66 66 // 'sdk-method-class-conflict.yaml', ··· 121 121 '/* eslint-disable */', 122 122 '// This file is auto-generated by @hey-api/openapi-ts', 123 123 ], 124 - // importFileExtension: '.js', 124 + importFileExtension: '.ts', 125 125 // indexFile: false, 126 126 // nameConflictResolver({ attempt, baseName }) { 127 127 // // console.log('resolving conflict for:', { attempt, baseName }); ··· 332 332 // fields.unwrap('path') 333 333 // }, 334 334 // include... 335 - // name: '@hey-api/sdk', 335 + name: '@hey-api/sdk', 336 336 operations: { 337 337 // container: 'object', 338 338 // containerName: {
+16 -3
dev/playground.ts
··· 1 1 import type { DefinePlugin, IR } from '@hey-api/openapi-ts'; 2 - import { createOpencode } from '@opencode-ai/sdk'; 2 + 3 + // import { createOpencode } from '@opencode-ai/sdk'; 4 + import { PetStore } from './.gen/sdk.gen.ts'; 3 5 4 6 type MyPluginConfig = { readonly name: 'myplugin' }; 5 7 type MyPlugin = DefinePlugin<MyPluginConfig>; ··· 15 17 }; 16 18 17 19 async function run() { 18 - const { client, server } = await createOpencode(); 19 - console.log(client, server); 20 + // const { client, server } = await createOpencode(); 21 + // console.log(client, server); 22 + const client = new PetStore(); 23 + client.tui.publish({ 24 + body: { 25 + properties: { 26 + message: 'Hello from Hey API OpenAPI TS Playground!', 27 + variant: 'success', 28 + }, 29 + type: 'tui.toast.show', 30 + }, 31 + directory: 'main', 32 + }); 20 33 } 21 34 22 35 run();
+2 -2
packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/sdk.gen.ts
··· 1703 1703 directory?: string; 1704 1704 body?: EventTuiPromptAppend | EventTuiCommandExecute | EventTuiToastShow; 1705 1705 }, options?: Options<never, ThrowOnError>) => { 1706 - const params = buildClientParams([parameters], [{ args: [{ in: 'query', key: 'directory' }, { in: 'body' }] }]); 1706 + const params = buildClientParams([parameters], [{ args: [{ in: 'query', key: 'directory' }, { key: 'body', map: 'body' }] }]); 1707 1707 return (options?.client ?? client).post<TuiPublishResponses, TuiPublishErrors, ThrowOnError>({ 1708 1708 url: '/tui/publish', 1709 1709 ...options, ··· 1741 1741 directory?: string; 1742 1742 body?: unknown; 1743 1743 }, options?: Options<never, ThrowOnError>) => { 1744 - const params = buildClientParams([parameters], [{ args: [{ in: 'query', key: 'directory' }, { in: 'body' }] }]); 1744 + const params = buildClientParams([parameters], [{ args: [{ in: 'query', key: 'directory' }, { key: 'body', map: 'body' }] }]); 1745 1745 return (options?.client ?? client).post<TuiControlResponseResponses, unknown, ThrowOnError>({ 1746 1746 url: '/tui/control/response', 1747 1747 ...options,
+2 -2
packages/openapi-ts-tests/sdks/__snapshots__/opencode/flat/sdk.gen.ts
··· 1703 1703 directory?: string; 1704 1704 body?: EventTuiPromptAppend | EventTuiCommandExecute | EventTuiToastShow; 1705 1705 }, options?: Options<never, ThrowOnError>) => { 1706 - const params = buildClientParams([parameters], [{ args: [{ in: 'query', key: 'directory' }, { in: 'body' }] }]); 1706 + const params = buildClientParams([parameters], [{ args: [{ in: 'query', key: 'directory' }, { key: 'body', map: 'body' }] }]); 1707 1707 return (options?.client ?? client).post<TuiPublishResponses, TuiPublishErrors, ThrowOnError>({ 1708 1708 url: '/tui/publish', 1709 1709 ...options, ··· 1741 1741 directory?: string; 1742 1742 body?: unknown; 1743 1743 }, options?: Options<never, ThrowOnError>) => { 1744 - const params = buildClientParams([parameters], [{ args: [{ in: 'query', key: 'directory' }, { in: 'body' }] }]); 1744 + const params = buildClientParams([parameters], [{ args: [{ in: 'query', key: 'directory' }, { key: 'body', map: 'body' }] }]); 1745 1745 return (options?.client ?? client).post<TuiControlResponseResponses, unknown, ThrowOnError>({ 1746 1746 url: '/tui/control/response', 1747 1747 ...options,
+6 -6
packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts
··· 76 76 parameters: Array<ReturnType<typeof $.param>>; 77 77 }; 78 78 79 - export const operationParameters = ({ 79 + export function operationParameters({ 80 80 isRequiredOptions, 81 81 operation, 82 82 plugin, ··· 84 84 isRequiredOptions: boolean; 85 85 operation: IR.OperationObject; 86 86 plugin: HeyApiSdkPlugin['Instance']; 87 - }): OperationParameters => { 87 + }): OperationParameters { 88 88 const result: OperationParameters = { 89 89 argNames: [], 90 90 fields: [], ··· 147 147 ); 148 148 149 149 return result; 150 - }; 150 + } 151 151 152 152 /** 153 153 * Infers `responseType` value from provided response content type. This is ··· 205 205 return; 206 206 }; 207 207 208 - export const operationStatements = ({ 208 + export function operationStatements({ 209 209 isRequiredOptions, 210 210 opParameters, 211 211 operation, ··· 215 215 opParameters: OperationParameters; 216 216 operation: IR.OperationObject; 217 217 plugin: HeyApiSdkPlugin['Instance']; 218 - }): Array<ReturnType<typeof $.return | typeof $.const>> => { 218 + }): Array<ReturnType<typeof $.return | typeof $.const>> { 219 219 const client = getClientPlugin(plugin.context.config); 220 220 const isNuxtClient = client.name === '@hey-api/client-nuxt'; 221 221 ··· 514 514 ); 515 515 516 516 return statements; 517 - }; 517 + }
+7 -4
packages/openapi-ts/src/plugins/@hey-api/sdk/shared/signature.ts
··· 38 38 * - Prefixes all conflicting names with their location (e.g. path_foo, query_foo) 39 39 * - Returns a flat map of resolved parameter names to their metadata 40 40 */ 41 - export const getSignatureParameters = ({ 41 + export function getSignatureParameters({ 42 42 operation, 43 43 }: { 44 44 operation: IR.OperationObject; 45 45 plugin: PluginInstance; 46 - }): Signature | undefined => { 46 + }): Signature | undefined { 47 47 // TODO: add cookies 48 48 const locations = [ 49 49 'header', ··· 181 181 name: 'body', 182 182 schema: operation.body.schema, 183 183 }; 184 - fields.push({ in: 'body' }); 184 + fields.push({ 185 + key: 'body', 186 + map: 'body', 187 + }); 185 188 } 186 189 } 187 190 ··· 190 193 } 191 194 192 195 return { fields, parameters: signatureParameters }; 193 - }; 196 + }