Skip to content

Commit d9dd389

Browse files
committed
feat(sdk): add paramsStructure option
1 parent 6d2622f commit d9dd389

File tree

424 files changed

+9435
-4822
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

424 files changed

+9435
-4822
lines changed

.changeset/nine-cats-cross.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+
fix(sdk): add paramsStructure field

.changeset/tidy-poets-peel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/codegen-core': patch
3+
---
4+
5+
fix: update types

dev/openapi-ts.config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export default defineConfig(() => {
4141
// 'invalid',
4242
// 'openai.yaml',
4343
// 'full.yaml',
44-
// 'opencode.yaml',
45-
'sdk-instance.yaml',
44+
'opencode.yaml',
45+
// 'sdk-instance.yaml',
4646
// 'string-with-format.yaml',
4747
// 'transformers.json',
4848
// 'type-format.yaml',
@@ -248,21 +248,21 @@ export default defineConfig(() => {
248248
// },
249249
},
250250
{
251-
asClass: true,
251+
// asClass: true,
252252
// auth: false,
253253
// classNameBuilder: '{{name}}',
254-
classNameBuilder: '{{name}}Service',
254+
// classNameBuilder: '{{name}}Service',
255255
// classStructure: 'off',
256256
// client: false,
257257
// getSignature: ({ fields, signature, operation }) => {
258258
// // ...
259259
// fields.unwrap('path')
260260
// },
261261
// include...
262-
// instance: true,
262+
instance: true,
263263
name: '@hey-api/sdk',
264264
// operationId: false,
265-
// params_EXPERIMENTAL: 'experiment',
265+
paramsStructure: 'flat',
266266
// responseStyle: 'data',
267267
// signature: 'auto',
268268
// signature: 'client',

dev/playground.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Sdk } from './.gen/sdk.gen';
2+
3+
const opencode = new Sdk();
4+
opencode.session.create(
5+
{
6+
parentID: '',
7+
title: '',
8+
},
9+
{
10+
headers: {
11+
'X-Custom-Header': 'value',
12+
},
13+
},
14+
);
15+
opencode.session.init({
16+
id: '',
17+
messageID: '',
18+
modelID: '',
19+
providerID: '',
20+
});
21+
opencode.session.chat({
22+
agent: '',
23+
id: '',
24+
messageID: '',
25+
modelID: '',
26+
parts: [
27+
{
28+
name: '',
29+
type: 'agent',
30+
},
31+
],
32+
providerID: '',
33+
system: '',
34+
tools: {},
35+
});
36+
opencode.auth.set({
37+
auth: {
38+
// access: '',
39+
// expires: 1,
40+
key: '',
41+
// refresh: '',
42+
// token: '',
43+
type: 'api',
44+
},
45+
id: '123',
46+
});
47+
opencode.postSessionByIdPermissionsByPermissionId({
48+
id: 'session-id',
49+
permissionID: 'permission-id',
50+
response: 'always',
51+
});
52+
opencode.tui.showToast({
53+
message: '',
54+
title: '',
55+
variant: 'error',
56+
});

packages/codegen-core/src/symbols/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface ISymbolIn {
3939
/**
4040
* Kind of symbol.
4141
*/
42-
readonly kind?: 'type';
42+
readonly kind?: 'class' | 'function' | 'type';
4343
/**
4444
* Arbitrary metadata about the symbol.
4545
*

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/client/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export type Options<
238238
RequestOptions<TResponse, TResponseStyle, ThrowOnError>,
239239
'body' | 'path' | 'query' | 'url'
240240
> &
241-
Omit<TData, 'url'>;
241+
([TData] extends [never] ? unknown : Omit<TData, 'url'>);
242242

243243
export type OptionsLegacyParser<
244244
TData = unknown,

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/core/params.gen.ts

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
type Slot = 'body' | 'headers' | 'path' | 'query';
44

5+
type Params = {
6+
body: unknown;
7+
headers: Record<string, unknown>;
8+
path: Record<string, unknown>;
9+
query: Record<string, unknown>;
10+
}
11+
12+
type KeyMap = Map<
13+
string,
14+
{
15+
in: Slot;
16+
map?: string;
17+
} | {
18+
in?: never;
19+
map: Slot;
20+
}
21+
>;
22+
523
export type Field =
624
| {
725
in: Exclude<Slot, 'body'>;
@@ -22,6 +40,17 @@ export type Field =
2240
*/
2341
key?: string;
2442
map?: string;
43+
}
44+
| {
45+
/**
46+
* Field name. This is the name we want the user to see and use.
47+
*/
48+
key: string;
49+
/**
50+
* Field mapped name. This is the name we want to use in the request.
51+
* If `in` is omitted, `map` aliases `key` to the transport layer.
52+
*/
53+
map: Slot;
2554
};
2655

2756
export interface Fields {
@@ -39,14 +68,6 @@ const extraPrefixesMap: Record<string, Slot> = {
3968
};
4069
const extraPrefixes = Object.entries(extraPrefixesMap);
4170

42-
type KeyMap = Map<
43-
string,
44-
{
45-
in: Slot;
46-
map?: string;
47-
}
48-
>;
49-
5071
const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
5172
if (!map) {
5273
map = new Map();
@@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
6081
map: config.map,
6182
});
6283
}
84+
} else if ('key' in config) {
85+
map.set(config.key, {
86+
map: config.map,
87+
});
6388
} else if (config.args) {
6489
buildKeyMap(config.args, map);
6590
}
@@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
6893
return map;
6994
};
7095

71-
interface Params {
72-
body: unknown;
73-
headers: Record<string, unknown>;
74-
path: Record<string, unknown>;
75-
query: Record<string, unknown>;
76-
}
77-
7896
const stripEmptySlots = (params: Params) => {
7997
for (const [slot, value] of Object.entries(params)) {
8098
if (value && typeof value === 'object' && !Object.keys(value).length) {
@@ -111,7 +129,9 @@ export const buildClientParams = (
111129
if (config.key) {
112130
const field = map.get(config.key)!;
113131
const name = field.map || config.key;
114-
(params[field.in] as Record<string, unknown>)[name] = arg;
132+
if (field.in) {
133+
(params[field.in] as Record<string, unknown>)[name] = arg;
134+
}
115135
} else {
116136
params.body = arg;
117137
}
@@ -120,8 +140,12 @@ export const buildClientParams = (
120140
const field = map.get(key);
121141

122142
if (field) {
123-
const name = field.map || key;
124-
(params[field.in] as Record<string, unknown>)[name] = value;
143+
if (field.in) {
144+
const name = field.map || key;
145+
(params[field.in] as Record<string, unknown>)[name] = value;
146+
} else {
147+
params[field.map] = value;
148+
}
125149
} else {
126150
const extra = extraPrefixes.find(([prefix]) =>
127151
key.startsWith(prefix),
@@ -132,10 +156,8 @@ export const buildClientParams = (
132156
(params[slot] as Record<string, unknown>)[
133157
key.slice(prefix.length)
134158
] = value;
135-
} else {
136-
for (const [slot, allowed] of Object.entries(
137-
config.allowExtra ?? {},
138-
)) {
159+
} else if ('allowExtra' in config && config.allowExtra) {
160+
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
139161
if (allowed) {
140162
(params[slot as Slot] as Record<string, unknown>)[key] = value;
141163
break;

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/client/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export type Options<
238238
RequestOptions<TResponse, TResponseStyle, ThrowOnError>,
239239
'body' | 'path' | 'query' | 'url'
240240
> &
241-
Omit<TData, 'url'>;
241+
([TData] extends [never] ? unknown : Omit<TData, 'url'>);
242242

243243
export type OptionsLegacyParser<
244244
TData = unknown,

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/core/params.gen.ts

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
type Slot = 'body' | 'headers' | 'path' | 'query';
44

5+
type Params = {
6+
body: unknown;
7+
headers: Record<string, unknown>;
8+
path: Record<string, unknown>;
9+
query: Record<string, unknown>;
10+
}
11+
12+
type KeyMap = Map<
13+
string,
14+
{
15+
in: Slot;
16+
map?: string;
17+
} | {
18+
in?: never;
19+
map: Slot;
20+
}
21+
>;
22+
523
export type Field =
624
| {
725
in: Exclude<Slot, 'body'>;
@@ -22,6 +40,17 @@ export type Field =
2240
*/
2341
key?: string;
2442
map?: string;
43+
}
44+
| {
45+
/**
46+
* Field name. This is the name we want the user to see and use.
47+
*/
48+
key: string;
49+
/**
50+
* Field mapped name. This is the name we want to use in the request.
51+
* If `in` is omitted, `map` aliases `key` to the transport layer.
52+
*/
53+
map: Slot;
2554
};
2655

2756
export interface Fields {
@@ -39,14 +68,6 @@ const extraPrefixesMap: Record<string, Slot> = {
3968
};
4069
const extraPrefixes = Object.entries(extraPrefixesMap);
4170

42-
type KeyMap = Map<
43-
string,
44-
{
45-
in: Slot;
46-
map?: string;
47-
}
48-
>;
49-
5071
const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
5172
if (!map) {
5273
map = new Map();
@@ -60,6 +81,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
6081
map: config.map,
6182
});
6283
}
84+
} else if ('key' in config) {
85+
map.set(config.key, {
86+
map: config.map,
87+
});
6388
} else if (config.args) {
6489
buildKeyMap(config.args, map);
6590
}
@@ -68,13 +93,6 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
6893
return map;
6994
};
7095

71-
interface Params {
72-
body: unknown;
73-
headers: Record<string, unknown>;
74-
path: Record<string, unknown>;
75-
query: Record<string, unknown>;
76-
}
77-
7896
const stripEmptySlots = (params: Params) => {
7997
for (const [slot, value] of Object.entries(params)) {
8098
if (value && typeof value === 'object' && !Object.keys(value).length) {
@@ -111,7 +129,9 @@ export const buildClientParams = (
111129
if (config.key) {
112130
const field = map.get(config.key)!;
113131
const name = field.map || config.key;
114-
(params[field.in] as Record<string, unknown>)[name] = arg;
132+
if (field.in) {
133+
(params[field.in] as Record<string, unknown>)[name] = arg;
134+
}
115135
} else {
116136
params.body = arg;
117137
}
@@ -120,8 +140,12 @@ export const buildClientParams = (
120140
const field = map.get(key);
121141

122142
if (field) {
123-
const name = field.map || key;
124-
(params[field.in] as Record<string, unknown>)[name] = value;
143+
if (field.in) {
144+
const name = field.map || key;
145+
(params[field.in] as Record<string, unknown>)[name] = value;
146+
} else {
147+
params[field.map] = value;
148+
}
125149
} else {
126150
const extra = extraPrefixes.find(([prefix]) =>
127151
key.startsWith(prefix),
@@ -132,10 +156,8 @@ export const buildClientParams = (
132156
(params[slot] as Record<string, unknown>)[
133157
key.slice(prefix.length)
134158
] = value;
135-
} else {
136-
for (const [slot, allowed] of Object.entries(
137-
config.allowExtra ?? {},
138-
)) {
159+
} else if ('allowExtra' in config && config.allowExtra) {
160+
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
139161
if (allowed) {
140162
(params[slot as Slot] as Record<string, unknown>)[key] = value;
141163
break;

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@angular/common/default-class/client/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export type Options<
253253
RequestOptions<TResponse, TResponseStyle, ThrowOnError>,
254254
'body' | 'path' | 'query' | 'url'
255255
> &
256-
Omit<TData, 'url'>;
256+
([TData] extends [never] ? unknown : Omit<TData, 'url'>);
257257

258258
export type OptionsLegacyParser<
259259
TData = unknown,

0 commit comments

Comments
 (0)