Skip to content

Commit ccefe43

Browse files
committed
chore: add migration notes
1 parent e436bc5 commit ccefe43

File tree

116 files changed

+260
-129
lines changed

Some content is hidden

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

116 files changed

+260
-129
lines changed

.changeset/long-keys-refuse.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@hey-api/openapi-ts': minor
3+
---
4+
5+
feat: added `client.baseUrl` option
6+
7+
### Added `client.baseUrl` option
8+
9+
You can use this option to configure the default base URL for the generated client. By default, we will attempt to resolve the first defined server or infer the base URL from the input path. If you'd like to preserve the previous behavior, set `baseUrl` to `false`.
10+
11+
```js
12+
export default {
13+
input: 'path/to/openapi.json',
14+
output: 'src/client',
15+
plugins: [{
16+
baseUrl: false, // [!code ++]
17+
name: '@hey-api/client-fetch',
18+
}],
19+
};
20+
```

.changeset/unlucky-moles-dance.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
---
2-
'@hey-api/client-axios': patch
3-
'@hey-api/client-fetch': patch
4-
'@hey-api/client-next': patch
5-
'@hey-api/client-nuxt': patch
2+
'@hey-api/client-axios': minor
3+
'@hey-api/client-fetch': minor
4+
'@hey-api/client-next': minor
5+
'@hey-api/client-nuxt': minor
6+
'@hey-api/openapi-ts': minor
67
---
78

89
fix: make createConfig, CreateClientConfig, and Config accept ClientOptions generic
10+
11+
### Added `ClientOptions` interface
12+
13+
The `Config` interface now accepts an optional generic extending `ClientOptions` instead of `boolean` type `ThrowOnError`.
14+
15+
```ts
16+
type Foo = Config<false> // [!code --]
17+
type Foo = Config<{ throwOnError: false }> // [!code ++]
18+
```

docs/openapi-ts/clients/axios.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ In our custom file, we need to export a `createClientConfig()` method. This func
106106
::: code-group
107107

108108
```ts [hey-api.ts]
109-
import type { CreateClientConfig } from '@hey-api/client-axios';
109+
import type { CreateClientConfig } from './client/client.gen';
110110

111111
export const createClientConfig: CreateClientConfig = (config) => ({
112112
...config,

docs/openapi-ts/clients/fetch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ In our custom file, we need to export a `createClientConfig()` method. This func
106106
::: code-group
107107

108108
```ts [hey-api.ts]
109-
import type { CreateClientConfig } from '@hey-api/client-fetch';
109+
import type { CreateClientConfig } from './client/client.gen';
110110

111111
export const createClientConfig: CreateClientConfig = (config) => ({
112112
...config,

docs/openapi-ts/clients/next-js.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ In our custom file, we need to export a `createClientConfig()` method. This func
102102
::: code-group
103103

104104
```ts [hey-api.ts]
105-
import type { CreateClientConfig } from '@hey-api/client-next';
105+
import type { CreateClientConfig } from './client/client.gen';
106106

107107
export const createClientConfig: CreateClientConfig = (config) => ({
108108
...config,

docs/openapi-ts/clients/nuxt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ In our custom file, we need to export a `createClientConfig()` method. This func
102102
::: code-group
103103

104104
```ts [hey-api.ts]
105-
import type { CreateClientConfig } from '@hey-api/client-nuxt';
105+
import type { CreateClientConfig } from './client/client.gen';
106106

107107
export const createClientConfig: CreateClientConfig = (config) => ({
108108
...config,

docs/openapi-ts/migrating.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,34 @@ 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.64.0
31+
32+
### Added `ClientOptions` interface
33+
34+
The `Config` interface now accepts an optional generic extending `ClientOptions` instead of `boolean` type `ThrowOnError`.
35+
36+
```ts
37+
type Foo = Config<false>; // [!code --]
38+
type Foo = Config<{ throwOnError: false }>; // [!code ++]
39+
```
40+
41+
### Added `client.baseUrl` option
42+
43+
You can use this option to configure the default base URL for the generated client. By default, we will attempt to resolve the first defined server or infer the base URL from the input path. If you'd like to preserve the previous behavior, set `baseUrl` to `false`.
44+
45+
```js
46+
export default {
47+
input: 'path/to/openapi.json',
48+
output: 'src/client',
49+
plugins: [
50+
{
51+
baseUrl: false, // [!code ++]
52+
name: '@hey-api/client-fetch',
53+
},
54+
],
55+
};
56+
```
57+
3058
## v0.63.0
3159

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

3-
import { createClient, createConfig } from '@hey-api/client-next';
3+
import {
4+
type ClientOptions as DefaultClientOptions,
5+
type Config,
6+
createClient,
7+
createConfig,
8+
} from '@hey-api/client-next';
49

510
import { createClientConfig } from '../hey-api';
11+
import type { ClientOptions } from './types.gen';
612

7-
export const client = createClient(createClientConfig(createConfig()));
13+
/**
14+
* The `createClientConfig()` function will be called on client initialization
15+
* and the returned object will become the client's initial configuration.
16+
*
17+
* You may want to initialize your client this way instead of calling
18+
* `setConfig()`. This is useful for example if you're using Next.js
19+
* to ensure your client always has the correct values.
20+
*/
21+
export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> =
22+
(
23+
override?: Config<DefaultClientOptions & T>,
24+
) => Config<Required<DefaultClientOptions> & T>;
25+
26+
export const client = createClient(
27+
createClientConfig(createConfig<ClientOptions>()),
28+
);

examples/openapi-ts-next/src/client/types.gen.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,3 +561,7 @@ export type UpdateUserResponses = {
561561
*/
562562
default: unknown;
563563
};
564+
565+
export type ClientOptions = {
566+
baseUrl: `${string}://${string}/v3` | (string & {});
567+
};

examples/openapi-ts-next/src/hey-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CreateClientConfig } from '@hey-api/client-next';
1+
import type { CreateClientConfig } from './client/client.gen';
22

33
export const createClientConfig: CreateClientConfig = (config) => ({
44
...config,

packages/openapi-ts/src/openApi/3.0.x/parser/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { parseOperation } from './operation';
1313
import { parametersArrayToObject, parseParameter } from './parameter';
1414
import { parseRequestBody } from './requestBody';
1515
import { parseSchema } from './schema';
16+
import { parseServers } from './server';
1617

1718
export const parseV3_0_X = (context: IR.Context<OpenApiV3_0_X>) => {
1819
const operationIds = new Map<string, string>();
@@ -99,9 +100,7 @@ export const parseV3_0_X = (context: IR.Context<OpenApiV3_0_X>) => {
99100
}
100101
}
101102

102-
if (context.spec.servers) {
103-
context.ir.servers = context.spec.servers;
104-
}
103+
parseServers({ context });
105104

106105
for (const path in context.spec.paths) {
107106
const pathItem = context.spec.paths[path as keyof PathsObject]!;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { IR } from '../../../ir/types';
2+
import { parseUrl } from '../../../utils/url';
3+
4+
export const parseServers = ({ context }: { context: IR.Context }) => {
5+
if (context.spec.servers) {
6+
context.ir.servers = context.spec.servers;
7+
return;
8+
}
9+
10+
if (typeof context.config.input.path === 'string') {
11+
const url = parseUrl(context.config.input.path);
12+
context.ir.servers = [
13+
{
14+
url: `${url.protocol ? `${url.protocol}://` : ''}${url.host}${url.port ? `:${url.port}` : ''}`,
15+
},
16+
];
17+
}
18+
19+
if (!context.ir.servers) {
20+
context.ir.servers = [
21+
{
22+
url: '/',
23+
},
24+
];
25+
}
26+
};

packages/openapi-ts/src/openApi/3.1.x/parser/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { parseOperation } from './operation';
1313
import { parametersArrayToObject, parseParameter } from './parameter';
1414
import { parseRequestBody } from './requestBody';
1515
import { parseSchema } from './schema';
16+
import { parseServers } from './server';
1617

1718
export const parseV3_1_X = (context: IR.Context<OpenApiV3_1_X>) => {
1819
const operationIds = new Map<string, string>();
@@ -99,9 +100,7 @@ export const parseV3_1_X = (context: IR.Context<OpenApiV3_1_X>) => {
99100
}
100101
}
101102

102-
if (context.spec.servers) {
103-
context.ir.servers = context.spec.servers;
104-
}
103+
parseServers({ context });
105104

106105
for (const path in context.spec.paths) {
107106
const pathItem = context.spec.paths[path as keyof PathsObject]!;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { IR } from '../../../ir/types';
2+
import { parseUrl } from '../../../utils/url';
3+
4+
export const parseServers = ({ context }: { context: IR.Context }) => {
5+
if (context.spec.servers) {
6+
context.ir.servers = context.spec.servers;
7+
return;
8+
}
9+
10+
if (typeof context.config.input.path === 'string') {
11+
const url = parseUrl(context.config.input.path);
12+
context.ir.servers = [
13+
{
14+
url: `${url.protocol ? `${url.protocol}://` : ''}${url.host}${url.port ? `:${url.port}` : ''}`,
15+
},
16+
];
17+
}
18+
19+
if (!context.ir.servers) {
20+
context.ir.servers = [
21+
{
22+
url: '/',
23+
},
24+
];
25+
}
26+
};

packages/openapi-ts/src/plugins/@hey-api/typescript/clientOptions.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,14 @@ export const createClientOptions = ({
5353
serverToBaseUrlType({ server }),
5454
);
5555

56-
if (!('strictBaseUrl' in client && client.strictBaseUrl)) {
57-
if (servers.length) {
58-
types.push(
59-
compiler.typeIntersectionNode({
60-
types: [stringType, ts.factory.createTypeLiteralNode([])],
61-
}),
62-
);
63-
} else {
64-
types.push(stringType);
65-
}
56+
if (!servers.length) {
57+
types.push(stringType);
58+
} else if (!('strictBaseUrl' in client && client.strictBaseUrl)) {
59+
types.push(
60+
compiler.typeIntersectionNode({
61+
types: [stringType, ts.factory.createTypeLiteralNode([])],
62+
}),
63+
);
6664
}
6765

6866
const typeClientOptions = compiler.typeAliasDeclaration({

packages/openapi-ts/test/__snapshots__/3.0.x/additional-properties-false/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ export type Baz = Foo & {
1313
};
1414

1515
export type ClientOptions = {
16-
baseUrl: string;
16+
baseUrl: `${string}://${string}` | (string & {});
1717
};

packages/openapi-ts/test/__snapshots__/3.0.x/additional-properties-true/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ export type Baz = Foo & {
1515
};
1616

1717
export type ClientOptions = {
18-
baseUrl: string;
18+
baseUrl: `${string}://${string}` | (string & {});
1919
};

packages/openapi-ts/test/__snapshots__/3.0.x/additional-properties-undefined/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export type Foo = {
77
};
88

99
export type ClientOptions = {
10-
baseUrl: string;
10+
baseUrl: `${string}://${string}` | (string & {});
1111
};

packages/openapi-ts/test/__snapshots__/3.0.x/array-items-one-of-length-1/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export type Foo = {
77
export type Bar = string;
88

99
export type ClientOptions = {
10-
baseUrl: string;
10+
baseUrl: `${string}://${string}` | (string & {});
1111
};

packages/openapi-ts/test/__snapshots__/3.0.x/body-response-text-plain/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ export type PostFooResponses = {
1717
export type PostFooResponse = PostFooResponses[keyof PostFooResponses];
1818

1919
export type ClientOptions = {
20-
baseUrl: string;
20+
baseUrl: `${string}://${string}` | (string & {});
2121
};

packages/openapi-ts/test/__snapshots__/3.0.x/case-PascalCase/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ export type GetFooResponses = {
8585
export type GetFooResponse = GetFooResponses[keyof GetFooResponses];
8686

8787
export type ClientOptions = {
88-
baseUrl: string;
88+
baseUrl: `${string}://${string}` | (string & {});
8989
};

packages/openapi-ts/test/__snapshots__/3.0.x/case-camelCase/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ export type getFooResponses = {
8585
export type getFooResponse = getFooResponses[keyof getFooResponses];
8686

8787
export type clientOptions = {
88-
baseUrl: string;
88+
baseUrl: `${string}://${string}` | (string & {});
8989
};

packages/openapi-ts/test/__snapshots__/3.0.x/case-snake_case/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ export type get_foo_responses = {
8585
export type get_foo_response = get_foo_responses[keyof get_foo_responses];
8686

8787
export type client_options = {
88-
baseUrl: string;
88+
baseUrl: `${string}://${string}` | (string & {});
8989
};

packages/openapi-ts/test/__snapshots__/3.0.x/case/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ export type GetFoo_Responses = {
8585
export type GetFoo_Response = GetFoo_Responses[keyof GetFoo_Responses];
8686

8787
export type ClientOptions = {
88-
baseUrl: string;
88+
baseUrl: `${string}://${string}` | (string & {});
8989
};

packages/openapi-ts/test/__snapshots__/3.0.x/components-request-bodies/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ export type PostFooResponses = {
2525
};
2626

2727
export type ClientOptions = {
28-
baseUrl: string;
28+
baseUrl: `${string}://${string}` | (string & {});
2929
};

packages/openapi-ts/test/__snapshots__/3.0.x/content-binary/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ export type GetBarResponses = {
2727
export type GetBarResponse = GetBarResponses[keyof GetBarResponses];
2828

2929
export type ClientOptions = {
30-
baseUrl: string;
30+
baseUrl: `${string}://${string}` | (string & {});
3131
};

packages/openapi-ts/test/__snapshots__/3.0.x/discriminator-all-of/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ export type QuxMapped = FooMapped & {
4545
};
4646

4747
export type ClientOptions = {
48-
baseUrl: string;
48+
baseUrl: `${string}://${string}` | (string & {});
4949
};

packages/openapi-ts/test/__snapshots__/3.0.x/discriminator-any-of/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ export type Quuz = ({
2424
} & Baz);
2525

2626
export type ClientOptions = {
27-
baseUrl: string;
27+
baseUrl: `${string}://${string}` | (string & {});
2828
};

packages/openapi-ts/test/__snapshots__/3.0.x/discriminator-one-of/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ export type Quuz = ({
2424
} & Baz);
2525

2626
export type ClientOptions = {
27-
baseUrl: string;
27+
baseUrl: `${string}://${string}` | (string & {});
2828
};

packages/openapi-ts/test/__snapshots__/3.0.x/enum-escape/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export type Foo = {
77
export type Bar = "foo'bar" | 'foo"bar';
88

99
export type ClientOptions = {
10-
baseUrl: string;
10+
baseUrl: `${string}://${string}` | (string & {});
1111
};

0 commit comments

Comments
 (0)