Skip to content

Commit 557769d

Browse files
committed
chore: add changeset
1 parent 3e8d8e8 commit 557769d

File tree

88 files changed

+8360
-53403
lines changed

Some content is hidden

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

88 files changed

+8360
-53403
lines changed

.changeset/cold-snails-end.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
'@hey-api/openapi-ts': minor
3+
---
4+
5+
feat(sdk): add `classStructure` option supporting dot or slash `operationId` notation when generating class-based SDKs
6+
7+
### Added `sdk.classStructure` option
8+
9+
When generating class-based SDKs, we now try to infer the ideal structure using `operationId` keywords. If you'd like to preserve the previous behavior, set `classStructure` to `off`.
10+
11+
```js
12+
export default {
13+
input: 'https://get.heyapi.dev/hey-api/backend',
14+
output: 'src/client',
15+
plugins: [
16+
// ...other plugins
17+
{
18+
classStructure: 'off',
19+
name: '@hey-api/sdk',
20+
},
21+
],
22+
};
23+
```

docs/openapi-ts/migrating.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,38 @@ This config option is deprecated and will be removed in favor of [clients](./cli
2727

2828
This config option is deprecated and will be removed.
2929

30+
## v0.72.0
31+
32+
### Added `sdk.classStructure` option
33+
34+
When generating class-based SDKs, we now try to infer the ideal structure using `operationId` keywords. If you'd like to preserve the previous behavior, set `classStructure` to `off`.
35+
36+
```js
37+
export default {
38+
input: 'https://get.heyapi.dev/hey-api/backend',
39+
output: 'src/client',
40+
plugins: [
41+
// ...other plugins
42+
{
43+
classStructure: 'off', // [!code ++]
44+
name: '@hey-api/sdk',
45+
},
46+
],
47+
};
48+
```
49+
3050
## v0.71.0
3151

3252
### Renamed `sdk.serviceNameBuilder` option
3353

3454
This option has been renamed to `sdk.classNameBuilder` to better represent its functionality. Additionally, it's no longer set by default. To preserve the previous behavior, update your configuration.
3555

3656
```js
37-
import { defaultPlugins } from '@hey-api/openapi-ts';
38-
3957
export default {
4058
input: 'https://get.heyapi.dev/hey-api/backend',
4159
output: 'src/client',
4260
plugins: [
43-
...defaultPlugins,
61+
// ...other plugins
4462
{
4563
classNameBuilder: '{{name}}Service', // [!code ++]
4664
name: '@hey-api/sdk',
@@ -259,14 +277,12 @@ The Fetch API client will return raw response body as `ReadableStream` when `Con
259277
When generating SDKs, you now have to specify `transformer` in order to modify response data. By default, adding `@hey-api/transformers` to your plugins will only produce additional output. To preserve the previous functionality, set `sdk.transformer` to `true`.
260278

261279
```js
262-
import { defaultPlugins } from '@hey-api/openapi-ts';
263-
264280
export default {
265281
client: '@hey-api/client-fetch',
266282
input: 'https://get.heyapi.dev/hey-api/backend',
267283
output: 'src/client',
268284
plugins: [
269-
...defaultPlugins,
285+
// ...other plugins
270286
{
271287
dates: true,
272288
name: '@hey-api/transformers',
@@ -302,15 +318,13 @@ export default {
302318
`@hey-api/schemas` has been removed from the default plugins. To continue using it, add it to your plugins array.
303319

304320
```js
305-
import { defaultPlugins } from '@hey-api/openapi-ts';
306-
307321
export default {
308322
client: '@hey-api/client-fetch',
309323
experimentalParser: true,
310324
input: 'https://get.heyapi.dev/hey-api/backend',
311325
output: 'src/client',
312326
plugins: [
313-
...defaultPlugins,
327+
// ...other plugins
314328
'@hey-api/schemas', // [!code ++]
315329
],
316330
};

packages/openapi-ts-tests/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/sdk.gen.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

33
import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';
4-
import type { FooPostData, FooPostResponses, FooPutData, FooPutResponses, FooBarPostData, FooBarPostResponses, FooBarPutData, FooBarPutResponses } from './types.gen';
4+
import type { GetFooData, GetFooResponses, FooPostData, FooPostResponses, FooPutData, FooPutResponses, GetFooBarData, GetFooBarResponses, FooBarPostData, FooBarPostResponses, FooBarPutData, FooBarPutResponses } from './types.gen';
55
import { client as _heyApiClient } from './client.gen';
66

77
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
@@ -30,6 +30,22 @@ class _HeyApiClient {
3030
}
3131
}
3232

33+
class Bar extends _HeyApiClient {
34+
public post<ThrowOnError extends boolean = false>(options?: Options<FooBarPostData, ThrowOnError>) {
35+
return (options?.client ?? this._client).post<FooBarPostResponses, unknown, ThrowOnError>({
36+
url: '/foo/bar',
37+
...options
38+
});
39+
}
40+
41+
public put<ThrowOnError extends boolean = false>(options?: Options<FooBarPutData, ThrowOnError>) {
42+
return (options?.client ?? this._client).put<FooBarPutResponses, unknown, ThrowOnError>({
43+
url: '/foo/bar',
44+
...options
45+
});
46+
}
47+
}
48+
3349
class Foo extends _HeyApiClient {
3450
public post<ThrowOnError extends boolean = false>(options?: Options<FooPostData, ThrowOnError>) {
3551
return (options?.client ?? this._client).post<FooPostResponses, unknown, ThrowOnError>({
@@ -47,22 +63,19 @@ class Foo extends _HeyApiClient {
4763
bar = new Bar({ client: this._client });
4864
}
4965

50-
class Bar extends _HeyApiClient {
51-
public post<ThrowOnError extends boolean = false>(options?: Options<FooBarPostData, ThrowOnError>) {
52-
return (options?.client ?? this._client).post<FooBarPostResponses, unknown, ThrowOnError>({
53-
url: '/foo/bar',
66+
export class Sdk extends _HeyApiClient {
67+
public getFoo<ThrowOnError extends boolean = false>(options?: Options<GetFooData, ThrowOnError>) {
68+
return (options?.client ?? this._client).get<GetFooResponses, unknown, ThrowOnError>({
69+
url: '/foo',
5470
...options
5571
});
5672
}
5773

58-
public put<ThrowOnError extends boolean = false>(options?: Options<FooBarPutData, ThrowOnError>) {
59-
return (options?.client ?? this._client).put<FooBarPutResponses, unknown, ThrowOnError>({
74+
public getFooBar<ThrowOnError extends boolean = false>(options?: Options<GetFooBarData, ThrowOnError>) {
75+
return (options?.client ?? this._client).get<GetFooBarResponses, unknown, ThrowOnError>({
6076
url: '/foo/bar',
6177
...options
6278
});
6379
}
64-
}
65-
66-
export class Sdk extends _HeyApiClient {
6780
foo = new Foo({ client: this._client });
6881
}

packages/openapi-ts-tests/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/types.gen.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3+
export type GetFooData = {
4+
body?: never;
5+
path?: never;
6+
query?: never;
7+
url: '/foo';
8+
};
9+
10+
export type GetFooResponses = {
11+
/**
12+
* OK
13+
*/
14+
200: string;
15+
};
16+
17+
export type GetFooResponse = GetFooResponses[keyof GetFooResponses];
18+
319
export type FooPostData = {
420
body?: never;
521
path?: never;
@@ -32,6 +48,22 @@ export type FooPutResponses = {
3248

3349
export type FooPutResponse = FooPutResponses[keyof FooPutResponses];
3450

51+
export type GetFooBarData = {
52+
body?: never;
53+
path?: never;
54+
query?: never;
55+
url: '/foo/bar';
56+
};
57+
58+
export type GetFooBarResponses = {
59+
/**
60+
* OK
61+
*/
62+
200: string;
63+
};
64+
65+
export type GetFooBarResponse = GetFooBarResponses[keyof GetFooBarResponses];
66+
3567
export type FooBarPostData = {
3668
body?: never;
3769
path?: never;

0 commit comments

Comments
 (0)