Skip to content

Commit 4a85711

Browse files
committed
test(openapi-ts-tests): add client-ofetch to clients matrix & snapshots
1 parent 4d984b5 commit 4a85711

File tree

149 files changed

+42386
-0
lines changed

Some content is hidden

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

149 files changed

+42386
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
4+
import { createClient } from '@hey-api/openapi-ts';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
const root = path.resolve(__dirname, '..');
10+
const getSpecsPath = () => path.resolve(root, '..', 'specs');
11+
12+
const version = '3.1.x';
13+
const namespace = 'clients';
14+
const clientName = '@hey-api/client-ofetch';
15+
const outputDir = path.join(
16+
root,
17+
'test',
18+
'generated',
19+
version,
20+
namespace,
21+
clientName,
22+
);
23+
24+
const createConfig = (userConfig) => ({
25+
...userConfig,
26+
input: path.join(getSpecsPath(), version, 'full.yaml'),
27+
logs: { level: 'silent' },
28+
output:
29+
typeof userConfig.output === 'string'
30+
? path.join(outputDir, userConfig.output)
31+
: {
32+
...userConfig.output,
33+
path: path.join(outputDir, userConfig.output.path),
34+
},
35+
});
36+
37+
const scenarios = [
38+
{
39+
config: createConfig({ output: 'default', plugins: [clientName] }),
40+
description: 'default output',
41+
},
42+
{
43+
config: createConfig({
44+
output: 'sdk-client-optional',
45+
plugins: [clientName, { client: true, name: '@hey-api/sdk' }],
46+
}),
47+
description: 'SDK with optional client option',
48+
},
49+
{
50+
config: createConfig({
51+
output: 'sdk-client-required',
52+
plugins: [clientName, { client: false, name: '@hey-api/sdk' }],
53+
}),
54+
description: 'SDK with required client option',
55+
},
56+
{
57+
config: createConfig({
58+
output: 'base-url-false',
59+
plugins: [{ baseUrl: false, name: clientName }, '@hey-api/typescript'],
60+
}),
61+
description: 'client without base URL',
62+
},
63+
{
64+
config: createConfig({
65+
output: 'base-url-number',
66+
plugins: [{ baseUrl: 0, name: clientName }, '@hey-api/typescript'],
67+
}),
68+
description: 'client with numeric base URL',
69+
},
70+
{
71+
config: createConfig({
72+
output: 'base-url-string',
73+
plugins: [
74+
{ baseUrl: 'https://foo.com', name: clientName },
75+
'@hey-api/typescript',
76+
],
77+
}),
78+
description: 'client with custom string base URL',
79+
},
80+
{
81+
config: createConfig({
82+
output: 'base-url-strict',
83+
plugins: [{ baseUrl: true, name: clientName }, '@hey-api/typescript'],
84+
}),
85+
description: 'client with strict base URL',
86+
},
87+
{
88+
config: createConfig({
89+
output: {
90+
path: 'tsconfig-nodenext-sdk',
91+
tsConfigPath: path.join(
92+
root,
93+
'test',
94+
'tsconfig',
95+
'tsconfig.nodenext.json',
96+
),
97+
},
98+
plugins: [clientName, '@hey-api/sdk'],
99+
}),
100+
description: 'SDK with NodeNext tsconfig',
101+
},
102+
{
103+
config: createConfig({
104+
output: { clean: false, path: 'clean-false' },
105+
plugins: [clientName, '@hey-api/sdk'],
106+
}),
107+
description: 'avoid appending extension multiple times | twice',
108+
},
109+
];
110+
111+
async function main() {
112+
for (const { config, description } of scenarios) {
113+
console.log('Generating:', description);
114+
await createClient(config);
115+
if (description.endsWith('twice')) {
116+
await createClient(config);
117+
}
118+
}
119+
// Generate SSE for ofetch as well (mirrors 3.1.x.test.ts scenario)
120+
const sseOut = path.join(root, 'test', 'generated', version, 'sse-ofetch');
121+
await createClient({
122+
input: path.join(getSpecsPath(), version, 'opencode.yaml'),
123+
logs: { level: 'silent' },
124+
output: sseOut,
125+
parser: { filters: { operations: { include: ['GET /event'] } } },
126+
plugins: [clientName, '@hey-api/sdk'],
127+
});
128+
}
129+
130+
main().catch((err) => {
131+
console.error(err);
132+
process.exit(1);
133+
});

packages/openapi-ts-tests/main/test/3.1.x.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,21 @@ describe(`OpenAPI ${version}`, () => {
903903
}),
904904
description: 'client with SSE (Fetch)',
905905
},
906+
{
907+
config: createConfig({
908+
input: 'opencode.yaml',
909+
output: 'sse-ofetch',
910+
parser: {
911+
filters: {
912+
operations: {
913+
include: ['GET /event'],
914+
},
915+
},
916+
},
917+
plugins: ['@hey-api/client-ofetch', '@hey-api/sdk'],
918+
}),
919+
description: 'client with SSE (ofetch)',
920+
},
906921
{
907922
config: createConfig({
908923
input: 'opencode.yaml',
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import type { ClientOptions } from './types.gen';
4+
import { type ClientOptions as DefaultClientOptions, type Config, createClient, createConfig } from './client';
5+
6+
/**
7+
* The `createClientConfig()` function will be called on client initialization
8+
* and the returned object will become the client's initial configuration.
9+
*
10+
* You may want to initialize your client this way instead of calling
11+
* `setConfig()`. This is useful for example if you're using Next.js
12+
* to ensure your client always has the correct values.
13+
*/
14+
export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = (override?: Config<DefaultClientOptions & T>) => Config<Required<DefaultClientOptions> & T>;
15+
16+
export const client = createClient(createConfig<ClientOptions>());

0 commit comments

Comments
 (0)