这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .changeset/nine-cats-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hey-api/openapi-ts': patch
---

fix(sdk): add paramsStructure field
5 changes: 5 additions & 0 deletions .changeset/tidy-poets-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hey-api/codegen-core': patch
---

fix: update types
12 changes: 6 additions & 6 deletions dev/openapi-ts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export default defineConfig(() => {
// 'invalid',
// 'openai.yaml',
// 'full.yaml',
// 'opencode.yaml',
'sdk-instance.yaml',
'opencode.yaml',
// 'sdk-instance.yaml',
// 'string-with-format.yaml',
// 'transformers.json',
// 'type-format.yaml',
Expand Down Expand Up @@ -248,21 +248,21 @@ export default defineConfig(() => {
// },
},
{
asClass: true,
// asClass: true,
// auth: false,
// classNameBuilder: '{{name}}',
classNameBuilder: '{{name}}Service',
// classNameBuilder: '{{name}}Service',
// classStructure: 'off',
// client: false,
// getSignature: ({ fields, signature, operation }) => {
// // ...
// fields.unwrap('path')
// },
// include...
// instance: true,
instance: true,
name: '@hey-api/sdk',
// operationId: false,
// params_EXPERIMENTAL: 'experiment',
paramsStructure: 'flat',
// responseStyle: 'data',
// signature: 'auto',
// signature: 'client',
Expand Down
56 changes: 56 additions & 0 deletions dev/playground.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Sdk } from './.gen/sdk.gen';

const opencode = new Sdk();
opencode.session.create(
{
parentID: '',
title: '',
},
{
headers: {
'X-Custom-Header': 'value',
},
},
);
opencode.session.init({
id: '',
messageID: '',
modelID: '',
providerID: '',
});
opencode.session.chat({
agent: '',
id: '',
messageID: '',
modelID: '',
parts: [
{
name: '',
type: 'agent',
},
],
providerID: '',
system: '',
tools: {},
});
opencode.auth.set({
auth: {
// access: '',
// expires: 1,
key: '',
// refresh: '',
// token: '',
type: 'api',
},
id: '123',
});
opencode.postSessionByIdPermissionsByPermissionId({
id: 'session-id',
permissionID: 'permission-id',
response: 'always',
});
opencode.tui.showToast({
message: '',
title: '',
variant: 'error',
});
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ type BuildUrlFn = <
url: string;
},
>(
options: Pick<TData, 'url'> & Options<TData>,
options: TData & Options<TData>,
) => string;

export type Client = CoreClient<
Expand Down Expand Up @@ -253,7 +253,7 @@ export type Options<
RequestOptions<TResponse, TResponseStyle, ThrowOnError>,
'body' | 'path' | 'query' | 'url'
> &
Omit<TData, 'url'>;
([TData] extends [never] ? unknown : Omit<TData, 'url'>);

export type OptionsLegacyParser<
TData = unknown,
Expand Down
45 changes: 34 additions & 11 deletions examples/openapi-ts-angular-common/src/client/core/params.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ export type Field =
*/
key?: string;
map?: string;
}
| {
/**
* Field name. This is the name we want the user to see and use.
*/
key: string;
/**
* Field mapped name. This is the name we want to use in the request.
* If `in` is omitted, `map` aliases `key` to the transport layer.
*/
map: Slot;
};

export interface Fields {
Expand All @@ -41,10 +52,14 @@ const extraPrefixes = Object.entries(extraPrefixesMap);

type KeyMap = Map<
string,
{
in: Slot;
map?: string;
}
| {
in: Slot;
map?: string;
}
| {
in?: never;
map: Slot;
}
>;

const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
Expand All @@ -60,6 +75,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
map: config.map,
});
}
} else if ('key' in config) {
map.set(config.key, {
map: config.map,
});
} else if (config.args) {
buildKeyMap(config.args, map);
}
Expand Down Expand Up @@ -111,7 +130,9 @@ export const buildClientParams = (
if (config.key) {
const field = map.get(config.key)!;
const name = field.map || config.key;
(params[field.in] as Record<string, unknown>)[name] = arg;
if (field.in) {
(params[field.in] as Record<string, unknown>)[name] = arg;
}
} else {
params.body = arg;
}
Expand All @@ -120,8 +141,12 @@ export const buildClientParams = (
const field = map.get(key);

if (field) {
const name = field.map || key;
(params[field.in] as Record<string, unknown>)[name] = value;
if (field.in) {
const name = field.map || key;
(params[field.in] as Record<string, unknown>)[name] = value;
} else {
params[field.map] = value;
}
} else {
const extra = extraPrefixes.find(([prefix]) =>
key.startsWith(prefix),
Expand All @@ -132,10 +157,8 @@ export const buildClientParams = (
(params[slot] as Record<string, unknown>)[
key.slice(prefix.length)
] = value;
} else {
for (const [slot, allowed] of Object.entries(
config.allowExtra ?? {},
)) {
} else if ('allowExtra' in config && config.allowExtra) {
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
if (allowed) {
(params[slot as Slot] as Record<string, unknown>)[key] = value;
break;
Expand Down
4 changes: 2 additions & 2 deletions examples/openapi-ts-angular/src/client/client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ type BuildUrlFn = <
url: string;
},
>(
options: Pick<TData, 'url'> & Options<TData>,
options: TData & Options<TData>,
) => string;

export type Client = CoreClient<
Expand Down Expand Up @@ -253,7 +253,7 @@ export type Options<
RequestOptions<TResponse, TResponseStyle, ThrowOnError>,
'body' | 'path' | 'query' | 'url'
> &
Omit<TData, 'url'>;
([TData] extends [never] ? unknown : Omit<TData, 'url'>);

export type OptionsLegacyParser<
TData = unknown,
Expand Down
45 changes: 34 additions & 11 deletions examples/openapi-ts-angular/src/client/core/params.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ export type Field =
*/
key?: string;
map?: string;
}
| {
/**
* Field name. This is the name we want the user to see and use.
*/
key: string;
/**
* Field mapped name. This is the name we want to use in the request.
* If `in` is omitted, `map` aliases `key` to the transport layer.
*/
map: Slot;
};

export interface Fields {
Expand All @@ -41,10 +52,14 @@ const extraPrefixes = Object.entries(extraPrefixesMap);

type KeyMap = Map<
string,
{
in: Slot;
map?: string;
}
| {
in: Slot;
map?: string;
}
| {
in?: never;
map: Slot;
}
>;

const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
Expand All @@ -60,6 +75,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
map: config.map,
});
}
} else if ('key' in config) {
map.set(config.key, {
map: config.map,
});
} else if (config.args) {
buildKeyMap(config.args, map);
}
Expand Down Expand Up @@ -111,7 +130,9 @@ export const buildClientParams = (
if (config.key) {
const field = map.get(config.key)!;
const name = field.map || config.key;
(params[field.in] as Record<string, unknown>)[name] = arg;
if (field.in) {
(params[field.in] as Record<string, unknown>)[name] = arg;
}
} else {
params.body = arg;
}
Expand All @@ -120,8 +141,12 @@ export const buildClientParams = (
const field = map.get(key);

if (field) {
const name = field.map || key;
(params[field.in] as Record<string, unknown>)[name] = value;
if (field.in) {
const name = field.map || key;
(params[field.in] as Record<string, unknown>)[name] = value;
} else {
params[field.map] = value;
}
} else {
const extra = extraPrefixes.find(([prefix]) =>
key.startsWith(prefix),
Expand All @@ -132,10 +157,8 @@ export const buildClientParams = (
(params[slot] as Record<string, unknown>)[
key.slice(prefix.length)
] = value;
} else {
for (const [slot, allowed] of Object.entries(
config.allowExtra ?? {},
)) {
} else if ('allowExtra' in config && config.allowExtra) {
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
if (allowed) {
(params[slot as Slot] as Record<string, unknown>)[key] = value;
break;
Expand Down
4 changes: 2 additions & 2 deletions examples/openapi-ts-axios/src/client/client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ type BuildUrlFn = <
url: string;
},
>(
options: Pick<TData, 'url'> & Options<TData>,
options: TData & Options<TData>,
) => string;

export type Client = CoreClient<
Expand Down Expand Up @@ -194,7 +194,7 @@ export type Options<
RequestOptions<TResponse, ThrowOnError>,
'body' | 'path' | 'query' | 'url'
> &
Omit<TData, 'url'>;
([TData] extends [never] ? unknown : Omit<TData, 'url'>);

export type OptionsLegacyParser<
TData = unknown,
Expand Down
Loading
Loading