Skip to content

Commit 9ec927a

Browse files
committed
test: update snapshots for improved error handling and enum generation
1 parent c476375 commit 9ec927a

File tree

160 files changed

+1436
-372
lines changed

Some content is hidden

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

160 files changed

+1436
-372
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,16 @@ export const createClient = (config: Config = {}): Client => {
143143
};
144144
}
145145

146-
let error = await response.text();
146+
const textError = await response.text();
147+
let jsonError: unknown;
147148

148149
try {
149-
error = JSON.parse(error);
150+
jsonError = JSON.parse(textError);
150151
} catch {
151152
// noop
152153
}
153154

155+
const error = jsonError ?? textError;
154156
let finalError = error;
155157

156158
for (const fn of interceptors.error._fns) {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@ type Slot = 'body' | 'headers' | 'path' | 'query';
33
export type Field =
44
| {
55
in: Exclude<Slot, 'body'>;
6+
/**
7+
* Field name. This is the name we want the user to see and use.
8+
*/
69
key: string;
10+
/**
11+
* Field mapped name. This is the name we want to use in the request.
12+
* If omitted, we use the same value as `key`.
13+
*/
714
map?: string;
815
}
916
| {
1017
in: Extract<Slot, 'body'>;
18+
/**
19+
* Key isn't required for bodies.
20+
*/
1121
key?: string;
1222
map?: string;
1323
};

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,17 @@ export interface Config {
102102
*/
103103
responseValidator?: (data: unknown) => Promise<unknown>;
104104
}
105+
106+
type IsExactlyNeverOrNeverUndefined<T> = [T] extends [never]
107+
? true
108+
: [T] extends [never | undefined]
109+
? [undefined] extends [T]
110+
? false
111+
: true
112+
: false;
113+
114+
export type OmitNever<T extends Record<string, unknown>> = {
115+
[K in keyof T as IsExactlyNeverOrNeverUndefined<T[K]> extends true
116+
? never
117+
: K]: T[K];
118+
};
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3-
export type _110 = '1-10' | '11-20';
4-
53
export const _110 = {
64
110: '1-10',
75
1120: '11-20'
86
} as const;
97

10-
export type MyFoo = 'myFoo' | 'myBar';
8+
export type _110 = typeof _110[keyof typeof _110];
119

1210
export const MyFoo = {
1311
MyFoo: 'myFoo',
1412
MyBar: 'myBar'
1513
} as const;
1614

17-
export type MyFoo2 = 'MyFoo' | 'MyBar';
15+
export type MyFoo = typeof MyFoo[keyof typeof MyFoo];
1816

1917
export const MyFoo2 = {
2018
MyFoo: 'MyFoo',
2119
MyBar: 'MyBar'
2220
} as const;
2321

24-
export type Foo = 'foo' | 'bar' | '' | true | false;
22+
export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2];
2523

2624
export const Foo = {
2725
Foo: 'foo',
@@ -31,7 +29,7 @@ export const Foo = {
3129
False: false
3230
} as const;
3331

34-
export type Numbers = 100 | 200 | 300 | -100 | -200 | -300;
32+
export type Foo = typeof Foo[keyof typeof Foo];
3533

3634
export const Numbers = {
3735
100: 100,
@@ -42,20 +40,16 @@ export const Numbers = {
4240
'-300': -300
4341
} as const;
4442

45-
export type Arrays = [
46-
'foo'
47-
] | [
48-
'bar'
49-
] | [
50-
'baz'
51-
];
43+
export type Numbers = typeof Numbers[keyof typeof Numbers];
5244

5345
export const Arrays = {
5446
0: ['foo'],
5547
1: ['bar'],
5648
2: ['baz']
5749
} as const;
5850

51+
export type Arrays = typeof Arrays[keyof typeof Arrays];
52+
5953
export type ClientOptions = {
6054
baseUrl: string;
6155
};
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3-
export type _110 = '1-10' | '11-20';
4-
53
export const _110 = {
64
'1_10': '1-10',
75
'11_20': '11-20'
86
} as const;
97

10-
export type MyFoo = 'myFoo' | 'myBar';
8+
export type _110 = typeof _110[keyof typeof _110];
119

1210
export const MyFoo = {
1311
MY_FOO: 'myFoo',
1412
MY_BAR: 'myBar'
1513
} as const;
1614

17-
export type MyFoo2 = 'MyFoo' | 'MyBar';
15+
export type MyFoo = typeof MyFoo[keyof typeof MyFoo];
1816

1917
export const MyFoo2 = {
2018
MY_FOO: 'MyFoo',
2119
MY_BAR: 'MyBar'
2220
} as const;
2321

24-
export type Foo = 'foo' | 'bar' | '' | true | false;
22+
export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2];
2523

2624
export const Foo = {
2725
FOO: 'foo',
@@ -31,7 +29,7 @@ export const Foo = {
3129
FALSE: false
3230
} as const;
3331

34-
export type Numbers = 100 | 200 | 300 | -100 | -200 | -300;
32+
export type Foo = typeof Foo[keyof typeof Foo];
3533

3634
export const Numbers = {
3735
100: 100,
@@ -42,20 +40,16 @@ export const Numbers = {
4240
'-300': -300
4341
} as const;
4442

45-
export type Arrays = [
46-
'foo'
47-
] | [
48-
'bar'
49-
] | [
50-
'baz'
51-
];
43+
export type Numbers = typeof Numbers[keyof typeof Numbers];
5244

5345
export const Arrays = {
5446
0: ['foo'],
5547
1: ['bar'],
5648
2: ['baz']
5749
} as const;
5850

51+
export type Arrays = typeof Arrays[keyof typeof Arrays];
52+
5953
export type ClientOptions = {
6054
baseUrl: string;
6155
};
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3-
export type _110 = '1-10' | '11-20';
4-
53
export const _110 = {
64
110: '1-10',
75
1120: '11-20'
86
} as const;
97

10-
export type MyFoo = 'myFoo' | 'myBar';
8+
export type _110 = typeof _110[keyof typeof _110];
119

1210
export const MyFoo = {
1311
myFoo: 'myFoo',
1412
myBar: 'myBar'
1513
} as const;
1614

17-
export type MyFoo2 = 'MyFoo' | 'MyBar';
15+
export type MyFoo = typeof MyFoo[keyof typeof MyFoo];
1816

1917
export const MyFoo2 = {
2018
myFoo: 'MyFoo',
2119
myBar: 'MyBar'
2220
} as const;
2321

24-
export type Foo = 'foo' | 'bar' | '' | true | false;
22+
export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2];
2523

2624
export const Foo = {
2725
foo: 'foo',
@@ -31,7 +29,7 @@ export const Foo = {
3129
false: false
3230
} as const;
3331

34-
export type Numbers = 100 | 200 | 300 | -100 | -200 | -300;
32+
export type Foo = typeof Foo[keyof typeof Foo];
3533

3634
export const Numbers = {
3735
100: 100,
@@ -42,20 +40,16 @@ export const Numbers = {
4240
'-300': -300
4341
} as const;
4442

45-
export type Arrays = [
46-
'foo'
47-
] | [
48-
'bar'
49-
] | [
50-
'baz'
51-
];
43+
export type Numbers = typeof Numbers[keyof typeof Numbers];
5244

5345
export const Arrays = {
5446
0: ['foo'],
5547
1: ['bar'],
5648
2: ['baz']
5749
} as const;
5850

51+
export type Arrays = typeof Arrays[keyof typeof Arrays];
52+
5953
export type ClientOptions = {
6054
baseUrl: string;
6155
};
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3-
export type _110 = '1-10' | '11-20';
4-
53
export const _110 = {
64
'1-10': '1-10',
75
'11-20': '11-20'
86
} as const;
97

10-
export type MyFoo = 'myFoo' | 'myBar';
8+
export type _110 = typeof _110[keyof typeof _110];
119

1210
export const MyFoo = {
1311
myFoo: 'myFoo',
1412
myBar: 'myBar'
1513
} as const;
1614

17-
export type MyFoo2 = 'MyFoo' | 'MyBar';
15+
export type MyFoo = typeof MyFoo[keyof typeof MyFoo];
1816

1917
export const MyFoo2 = {
2018
MyFoo: 'MyFoo',
2119
MyBar: 'MyBar'
2220
} as const;
2321

24-
export type Foo = 'foo' | 'bar' | '' | true | false;
22+
export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2];
2523

2624
export const Foo = {
2725
foo: 'foo',
@@ -31,7 +29,7 @@ export const Foo = {
3129
false: false
3230
} as const;
3331

34-
export type Numbers = 100 | 200 | 300 | -100 | -200 | -300;
32+
export type Foo = typeof Foo[keyof typeof Foo];
3533

3634
export const Numbers = {
3735
100: 100,
@@ -42,20 +40,16 @@ export const Numbers = {
4240
'-300': -300
4341
} as const;
4442

45-
export type Arrays = [
46-
'foo'
47-
] | [
48-
'bar'
49-
] | [
50-
'baz'
51-
];
43+
export type Numbers = typeof Numbers[keyof typeof Numbers];
5244

5345
export const Arrays = {
5446
0: ['foo'],
5547
1: ['bar'],
5648
2: ['baz']
5749
} as const;
5850

51+
export type Arrays = typeof Arrays[keyof typeof Arrays];
52+
5953
export type ClientOptions = {
6054
baseUrl: string;
6155
};
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3-
export type _110 = '1-10' | '11-20';
4-
53
export const _110 = {
64
'1_10': '1-10',
75
'11_20': '11-20'
86
} as const;
97

10-
export type MyFoo = 'myFoo' | 'myBar';
8+
export type _110 = typeof _110[keyof typeof _110];
119

1210
export const MyFoo = {
1311
my_foo: 'myFoo',
1412
my_bar: 'myBar'
1513
} as const;
1614

17-
export type MyFoo2 = 'MyFoo' | 'MyBar';
15+
export type MyFoo = typeof MyFoo[keyof typeof MyFoo];
1816

1917
export const MyFoo2 = {
2018
my_foo: 'MyFoo',
2119
my_bar: 'MyBar'
2220
} as const;
2321

24-
export type Foo = 'foo' | 'bar' | '' | true | false;
22+
export type MyFoo2 = typeof MyFoo2[keyof typeof MyFoo2];
2523

2624
export const Foo = {
2725
foo: 'foo',
@@ -31,7 +29,7 @@ export const Foo = {
3129
false: false
3230
} as const;
3331

34-
export type Numbers = 100 | 200 | 300 | -100 | -200 | -300;
32+
export type Foo = typeof Foo[keyof typeof Foo];
3533

3634
export const Numbers = {
3735
100: 100,
@@ -42,20 +40,16 @@ export const Numbers = {
4240
'-300': -300
4341
} as const;
4442

45-
export type Arrays = [
46-
'foo'
47-
] | [
48-
'bar'
49-
] | [
50-
'baz'
51-
];
43+
export type Numbers = typeof Numbers[keyof typeof Numbers];
5244

5345
export const Arrays = {
5446
0: ['foo'],
5547
1: ['bar'],
5648
2: ['baz']
5749
} as const;
5850

51+
export type Arrays = typeof Arrays[keyof typeof Arrays];
52+
5953
export type ClientOptions = {
6054
baseUrl: string;
6155
};

0 commit comments

Comments
 (0)