Skip to content

Commit 14d7ec9

Browse files
committed
feat(parser): add enums transforms
1 parent d901bd5 commit 14d7ec9

File tree

22 files changed

+1092
-200
lines changed

22 files changed

+1092
-200
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3+
export type Foo = {
4+
type?: Type;
5+
};
6+
37
export type Type = 'foo' | 'bar';
48

59
export const Type = {
610
FOO: 'foo',
711
BAR: 'bar'
812
} as const;
913

10-
export type Foo = {
11-
type?: 'foo' | 'bar';
12-
};
13-
1414
export type ClientOptions = {
1515
baseUrl: `${string}://${string}` | (string & {});
1616
};
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3-
export namespace Foo {
4-
export enum Type {
5-
FOO = 'foo',
6-
BAR = 'bar'
7-
}
8-
}
9-
103
export type Foo = {
11-
type?: 'foo' | 'bar';
4+
type?: Type;
125
};
136

7+
export enum Type {
8+
FOO = 'foo',
9+
BAR = 'bar'
10+
}
11+
1412
export type ClientOptions = {
1513
baseUrl: `${string}://${string}` | (string & {});
1614
};
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3+
export type Foo = {
4+
type?: Type;
5+
};
6+
37
export enum Type {
48
FOO = 'foo',
59
BAR = 'bar'
610
}
711

8-
export type Foo = {
9-
type?: 'foo' | 'bar';
10-
};
11-
1212
export type ClientOptions = {
1313
baseUrl: `${string}://${string}` | (string & {});
1414
};
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

33
export type Foo = {
4-
type?: 'foo' | 'bar';
4+
type?: Type;
55
};
66

7+
export type Type = 'foo' | 'bar';
8+
79
export type ClientOptions = {
810
baseUrl: `${string}://${string}` | (string & {});
911
};
Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3+
export type Foo = {
4+
type?: Type;
5+
};
6+
7+
export type Bar = {
8+
type?: Baz;
9+
};
10+
11+
export type Baz = 'qux' | 'quux';
12+
13+
export const Baz = {
14+
QUX: 'qux',
15+
QUUX: 'quux'
16+
} as const;
17+
318
export type Type = 'foo' | 'bar';
419

520
export const Type = {
621
FOO: 'foo',
722
BAR: 'bar'
823
} as const;
924

10-
export type Foo = {
11-
type?: 'foo' | 'bar';
12-
};
25+
export type Foo2 = 'foo' | 'bar';
26+
27+
export const Foo = {
28+
FOO: 'foo',
29+
BAR: 'bar'
30+
} as const;
31+
32+
export type Foo1 = 'baz';
33+
34+
export const Foo1 = {
35+
BAZ: 'baz'
36+
} as const;
1337

1438
export type GetFooData = {
1539
body?: never;
@@ -18,19 +42,12 @@ export type GetFooData = {
1842
url: '/foo';
1943
};
2044

21-
export type Foo2 = 'foo' | 'bar';
22-
23-
export const Foo = {
24-
FOO: 'foo',
25-
BAR: 'bar'
26-
} as const;
27-
2845
export type GetFooResponses = {
2946
/**
3047
* OK
3148
*/
3249
200: {
33-
foo?: 'foo' | 'bar';
50+
foo?: Foo2;
3451
};
3552
};
3653

@@ -43,23 +60,33 @@ export type PostFooData = {
4360
url: '/foo';
4461
};
4562

46-
export type Foo3 = 'baz';
47-
48-
export const Foo2 = {
49-
BAZ: 'baz'
50-
} as const;
51-
5263
export type PostFooResponses = {
5364
/**
5465
* OK
5566
*/
5667
200: {
57-
foo?: 'baz';
68+
foo?: Foo1;
5869
};
5970
};
6071

6172
export type PostFooResponse = PostFooResponses[keyof PostFooResponses];
6273

74+
export type PutFooData = {
75+
body?: never;
76+
path?: never;
77+
query?: never;
78+
url: '/foo';
79+
};
80+
81+
export type PutFooResponses = {
82+
/**
83+
* OK
84+
*/
85+
200: Baz;
86+
};
87+
88+
export type PutFooResponse = PutFooResponses[keyof PutFooResponses];
89+
6390
export type ClientOptions = {
6491
baseUrl: `${string}://${string}` | (string & {});
6592
};

packages/openapi-ts-tests/test/__snapshots__/3.1.x/enum-inline-typescript-namespace/types.gen.ts

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

3-
export namespace Foo {
4-
export enum Type {
5-
FOO = 'foo',
6-
BAR = 'bar'
7-
}
8-
}
9-
103
export type Foo = {
11-
type?: 'foo' | 'bar';
4+
type?: Type;
5+
};
6+
7+
export type Bar = {
8+
type?: Baz;
129
};
1310

11+
export enum Baz {
12+
QUX = 'qux',
13+
QUUX = 'quux'
14+
}
15+
16+
export enum Type {
17+
FOO = 'foo',
18+
BAR = 'bar'
19+
}
20+
21+
export enum Foo2 {
22+
FOO = 'foo',
23+
BAR = 'bar'
24+
}
25+
26+
export enum Foo1 {
27+
BAZ = 'baz'
28+
}
29+
1430
export type GetFooData = {
1531
body?: never;
1632
path?: never;
@@ -23,7 +39,7 @@ export type GetFooResponses = {
2339
* OK
2440
*/
2541
200: {
26-
foo?: 'foo' | 'bar';
42+
foo?: Foo2;
2743
};
2844
};
2945

@@ -41,12 +57,28 @@ export type PostFooResponses = {
4157
* OK
4258
*/
4359
200: {
44-
foo?: 'baz';
60+
foo?: Foo1;
4561
};
4662
};
4763

4864
export type PostFooResponse = PostFooResponses[keyof PostFooResponses];
4965

66+
export type PutFooData = {
67+
body?: never;
68+
path?: never;
69+
query?: never;
70+
url: '/foo';
71+
};
72+
73+
export type PutFooResponses = {
74+
/**
75+
* OK
76+
*/
77+
200: Baz;
78+
};
79+
80+
export type PutFooResponse = PutFooResponses[keyof PutFooResponses];
81+
5082
export type ClientOptions = {
5183
baseUrl: `${string}://${string}` | (string & {});
5284
};
Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

3+
export type Foo = {
4+
type?: Type;
5+
};
6+
7+
export type Bar = {
8+
type?: Baz;
9+
};
10+
11+
export enum Baz {
12+
QUX = 'qux',
13+
QUUX = 'quux'
14+
}
15+
316
export enum Type {
417
FOO = 'foo',
518
BAR = 'bar'
619
}
720

8-
export type Foo = {
9-
type?: 'foo' | 'bar';
10-
};
21+
export enum Foo2 {
22+
FOO = 'foo',
23+
BAR = 'bar'
24+
}
25+
26+
export enum Foo1 {
27+
BAZ = 'baz'
28+
}
1129

1230
export type GetFooData = {
1331
body?: never;
@@ -16,17 +34,12 @@ export type GetFooData = {
1634
url: '/foo';
1735
};
1836

19-
export enum Foo2 {
20-
FOO = 'foo',
21-
BAR = 'bar'
22-
}
23-
2437
export type GetFooResponses = {
2538
/**
2639
* OK
2740
*/
2841
200: {
29-
foo?: 'foo' | 'bar';
42+
foo?: Foo2;
3043
};
3144
};
3245

@@ -39,21 +52,33 @@ export type PostFooData = {
3952
url: '/foo';
4053
};
4154

42-
export enum Foo3 {
43-
BAZ = 'baz'
44-
}
45-
4655
export type PostFooResponses = {
4756
/**
4857
* OK
4958
*/
5059
200: {
51-
foo?: 'baz';
60+
foo?: Foo1;
5261
};
5362
};
5463

5564
export type PostFooResponse = PostFooResponses[keyof PostFooResponses];
5665

66+
export type PutFooData = {
67+
body?: never;
68+
path?: never;
69+
query?: never;
70+
url: '/foo';
71+
};
72+
73+
export type PutFooResponses = {
74+
/**
75+
* OK
76+
*/
77+
200: Baz;
78+
};
79+
80+
export type PutFooResponse = PutFooResponses[keyof PutFooResponses];
81+
5782
export type ClientOptions = {
5883
baseUrl: `${string}://${string}` | (string & {});
5984
};

0 commit comments

Comments
 (0)