Skip to content

Commit 7a04b27

Browse files
authored
Merge pull request #3255 from jsjames/fix-body-param
handle case where paramsStructure = 'flat' and body is an param.
2 parents f9303ff + 9ca5471 commit 7a04b27

File tree

7 files changed

+44
-23
lines changed

7 files changed

+44
-23
lines changed

.changeset/stale-parts-warn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
**plugin(@hey-api/sdk)**: correctly map body keys in flat mode

dev/openapi-ts.config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export default defineConfig(() => {
4848
path: path.resolve(
4949
getSpecsPath(),
5050
// '2.0.x',
51-
'3.0.x',
52-
// '3.1.x',
51+
// '3.0.x',
52+
'3.1.x',
5353
// 'circular.yaml',
5454
// 'dutchie.json',
5555
// 'enum-names-values.yaml',
@@ -58,9 +58,9 @@ export default defineConfig(() => {
5858
// 'invalid',
5959
// 'object-property-names.yaml',
6060
// 'openai.yaml',
61-
// 'opencode.yaml',
61+
'opencode.yaml',
6262
// 'pagination-ref.yaml',
63-
'ref-deep.yaml',
63+
// 'ref-deep.yaml',
6464
// 'schema-const.yaml',
6565
// 'sdk-instance.yaml',
6666
// 'sdk-method-class-conflict.yaml',
@@ -121,7 +121,7 @@ export default defineConfig(() => {
121121
'/* eslint-disable */',
122122
'// This file is auto-generated by @hey-api/openapi-ts',
123123
],
124-
// importFileExtension: '.js',
124+
importFileExtension: '.ts',
125125
// indexFile: false,
126126
// nameConflictResolver({ attempt, baseName }) {
127127
// // console.log('resolving conflict for:', { attempt, baseName });
@@ -332,7 +332,7 @@ export default defineConfig(() => {
332332
// fields.unwrap('path')
333333
// },
334334
// include...
335-
// name: '@hey-api/sdk',
335+
name: '@hey-api/sdk',
336336
operations: {
337337
// container: 'object',
338338
// containerName: {

dev/playground.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
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';
35

46
type MyPluginConfig = { readonly name: 'myplugin' };
57
type MyPlugin = DefinePlugin<MyPluginConfig>;
@@ -15,8 +17,19 @@ export const handler: MyPlugin['Handler'] = ({ plugin }) => {
1517
};
1618

1719
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+
});
2033
}
2134

2235
run();

packages/openapi-ts-tests/sdks/__snapshots__/opencode/export-all/sdk.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,7 @@ export const tuiPublish = <ThrowOnError extends boolean = false>(parameters?: {
17031703
directory?: string;
17041704
body?: EventTuiPromptAppend | EventTuiCommandExecute | EventTuiToastShow;
17051705
}, 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' }] }]);
17071707
return (options?.client ?? client).post<TuiPublishResponses, TuiPublishErrors, ThrowOnError>({
17081708
url: '/tui/publish',
17091709
...options,
@@ -1741,7 +1741,7 @@ export const tuiControlResponse = <ThrowOnError extends boolean = false>(paramet
17411741
directory?: string;
17421742
body?: unknown;
17431743
}, 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' }] }]);
17451745
return (options?.client ?? client).post<TuiControlResponseResponses, unknown, ThrowOnError>({
17461746
url: '/tui/control/response',
17471747
...options,

packages/openapi-ts-tests/sdks/__snapshots__/opencode/flat/sdk.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,7 @@ export const tuiPublish = <ThrowOnError extends boolean = false>(parameters?: {
17031703
directory?: string;
17041704
body?: EventTuiPromptAppend | EventTuiCommandExecute | EventTuiToastShow;
17051705
}, 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' }] }]);
17071707
return (options?.client ?? client).post<TuiPublishResponses, TuiPublishErrors, ThrowOnError>({
17081708
url: '/tui/publish',
17091709
...options,
@@ -1741,7 +1741,7 @@ export const tuiControlResponse = <ThrowOnError extends boolean = false>(paramet
17411741
directory?: string;
17421742
body?: unknown;
17431743
}, 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' }] }]);
17451745
return (options?.client ?? client).post<TuiControlResponseResponses, unknown, ThrowOnError>({
17461746
url: '/tui/control/response',
17471747
...options,

packages/openapi-ts/src/plugins/@hey-api/sdk/shared/operation.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ type OperationParameters = {
7676
parameters: Array<ReturnType<typeof $.param>>;
7777
};
7878

79-
export const operationParameters = ({
79+
export function operationParameters({
8080
isRequiredOptions,
8181
operation,
8282
plugin,
8383
}: {
8484
isRequiredOptions: boolean;
8585
operation: IR.OperationObject;
8686
plugin: HeyApiSdkPlugin['Instance'];
87-
}): OperationParameters => {
87+
}): OperationParameters {
8888
const result: OperationParameters = {
8989
argNames: [],
9090
fields: [],
@@ -147,7 +147,7 @@ export const operationParameters = ({
147147
);
148148

149149
return result;
150-
};
150+
}
151151

152152
/**
153153
* Infers `responseType` value from provided response content type. This is
@@ -205,7 +205,7 @@ const getResponseType = (
205205
return;
206206
};
207207

208-
export const operationStatements = ({
208+
export function operationStatements({
209209
isRequiredOptions,
210210
opParameters,
211211
operation,
@@ -215,7 +215,7 @@ export const operationStatements = ({
215215
opParameters: OperationParameters;
216216
operation: IR.OperationObject;
217217
plugin: HeyApiSdkPlugin['Instance'];
218-
}): Array<ReturnType<typeof $.return | typeof $.const>> => {
218+
}): Array<ReturnType<typeof $.return | typeof $.const>> {
219219
const client = getClientPlugin(plugin.context.config);
220220
const isNuxtClient = client.name === '@hey-api/client-nuxt';
221221

@@ -514,4 +514,4 @@ export const operationStatements = ({
514514
);
515515

516516
return statements;
517-
};
517+
}

packages/openapi-ts/src/plugins/@hey-api/sdk/shared/signature.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ type Signature = {
3838
* - Prefixes all conflicting names with their location (e.g. path_foo, query_foo)
3939
* - Returns a flat map of resolved parameter names to their metadata
4040
*/
41-
export const getSignatureParameters = ({
41+
export function getSignatureParameters({
4242
operation,
4343
}: {
4444
operation: IR.OperationObject;
4545
plugin: PluginInstance;
46-
}): Signature | undefined => {
46+
}): Signature | undefined {
4747
// TODO: add cookies
4848
const locations = [
4949
'header',
@@ -181,7 +181,10 @@ export const getSignatureParameters = ({
181181
name: 'body',
182182
schema: operation.body.schema,
183183
};
184-
fields.push({ in: 'body' });
184+
fields.push({
185+
key: 'body',
186+
map: 'body',
187+
});
185188
}
186189
}
187190

@@ -190,4 +193,4 @@ export const getSignatureParameters = ({
190193
}
191194

192195
return { fields, parameters: signatureParameters };
193-
};
196+
}

0 commit comments

Comments
 (0)