Skip to content

Commit cb70338

Browse files
authored
Merge pull request #1906 from hey-api/feat/exclude-deprecated
fix: support excluding deprecated fields
2 parents a60e58f + d1928d1 commit cb70338

File tree

20 files changed

+477
-142
lines changed

20 files changed

+477
-142
lines changed

.changeset/spotty-garlics-burn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
fix: exclude and include expressions can be an array

.changeset/wicked-zoos-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
fix: support excluding deprecated fields with '@deprecated'

packages/openapi-ts-tests/test/2.0.x.test.ts

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,34 @@ const version = '2.0.x';
1515
const outputDir = path.join(__dirname, 'generated', version);
1616

1717
describe(`OpenAPI ${version}`, () => {
18-
const createConfig = (userConfig: UserConfig): UserConfig => ({
19-
plugins: ['@hey-api/typescript'],
20-
...userConfig,
21-
input: path.join(
18+
const createConfig = (userConfig: UserConfig): UserConfig => {
19+
const inputPath = path.join(
2220
__dirname,
2321
'spec',
2422
version,
25-
typeof userConfig.input === 'string' ? userConfig.input : '',
26-
),
27-
logs: {
28-
level: 'silent',
29-
},
30-
output: path.join(
31-
outputDir,
32-
typeof userConfig.output === 'string' ? userConfig.output : '',
33-
),
34-
});
23+
typeof userConfig.input === 'string'
24+
? userConfig.input
25+
: (userConfig.input.path as string),
26+
);
27+
return {
28+
plugins: ['@hey-api/typescript'],
29+
...userConfig,
30+
input:
31+
typeof userConfig.input === 'string'
32+
? inputPath
33+
: {
34+
...userConfig.input,
35+
path: inputPath,
36+
},
37+
logs: {
38+
level: 'silent',
39+
},
40+
output: path.join(
41+
outputDir,
42+
typeof userConfig.output === 'string' ? userConfig.output : '',
43+
),
44+
};
45+
};
3546

3647
const scenarios = [
3748
{
@@ -203,6 +214,16 @@ describe(`OpenAPI ${version}`, () => {
203214
description:
204215
'handles various enum names and values (TypeScript, preserve)',
205216
},
217+
{
218+
config: createConfig({
219+
input: {
220+
exclude: ['@deprecated'],
221+
path: 'exclude-deprecated.yaml',
222+
},
223+
output: 'exclude-deprecated',
224+
}),
225+
description: 'excludes deprecated fields',
226+
},
206227
{
207228
config: createConfig({
208229
input: 'form-data.json',

packages/openapi-ts-tests/test/3.0.x.test.ts

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,34 @@ const version = '3.0.x';
1515
const outputDir = path.join(__dirname, 'generated', version);
1616

1717
describe(`OpenAPI ${version}`, () => {
18-
const createConfig = (userConfig: UserConfig): UserConfig => ({
19-
plugins: ['@hey-api/typescript'],
20-
...userConfig,
21-
input: path.join(
18+
const createConfig = (userConfig: UserConfig): UserConfig => {
19+
const inputPath = path.join(
2220
__dirname,
2321
'spec',
2422
version,
25-
typeof userConfig.input === 'string' ? userConfig.input : '',
26-
),
27-
logs: {
28-
level: 'silent',
29-
},
30-
output: path.join(
31-
outputDir,
32-
typeof userConfig.output === 'string' ? userConfig.output : '',
33-
),
34-
});
23+
typeof userConfig.input === 'string'
24+
? userConfig.input
25+
: (userConfig.input.path as string),
26+
);
27+
return {
28+
plugins: ['@hey-api/typescript'],
29+
...userConfig,
30+
input:
31+
typeof userConfig.input === 'string'
32+
? inputPath
33+
: {
34+
...userConfig.input,
35+
path: inputPath,
36+
},
37+
logs: {
38+
level: 'silent',
39+
},
40+
output: path.join(
41+
outputDir,
42+
typeof userConfig.output === 'string' ? userConfig.output : '',
43+
),
44+
};
45+
};
3546

3647
const scenarios = [
3748
{
@@ -388,6 +399,16 @@ describe(`OpenAPI ${version}`, () => {
388399
}),
389400
description: 'handles null enums',
390401
},
402+
{
403+
config: createConfig({
404+
input: {
405+
exclude: ['@deprecated'],
406+
path: 'exclude-deprecated.yaml',
407+
},
408+
output: 'exclude-deprecated',
409+
}),
410+
description: 'excludes deprecated fields',
411+
},
391412
{
392413
config: createConfig({
393414
input: 'internal-name-conflict.json',

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

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,34 @@ const version = '3.1.x';
1515
const outputDir = path.join(__dirname, 'generated', version);
1616

1717
describe(`OpenAPI ${version}`, () => {
18-
const createConfig = (userConfig: UserConfig): UserConfig => ({
19-
plugins: ['@hey-api/typescript'],
20-
...userConfig,
21-
input: path.join(
18+
const createConfig = (userConfig: UserConfig): UserConfig => {
19+
const inputPath = path.join(
2220
__dirname,
2321
'spec',
2422
version,
25-
typeof userConfig.input === 'string' ? userConfig.input : '',
26-
),
27-
logs: {
28-
level: 'silent',
29-
},
30-
output: path.join(
31-
outputDir,
32-
typeof userConfig.output === 'string' ? userConfig.output : '',
33-
),
34-
});
23+
typeof userConfig.input === 'string'
24+
? userConfig.input
25+
: (userConfig.input.path as string),
26+
);
27+
return {
28+
plugins: ['@hey-api/typescript'],
29+
...userConfig,
30+
input:
31+
typeof userConfig.input === 'string'
32+
? inputPath
33+
: {
34+
...userConfig.input,
35+
path: inputPath,
36+
},
37+
logs: {
38+
level: 'silent',
39+
},
40+
output: path.join(
41+
outputDir,
42+
typeof userConfig.output === 'string' ? userConfig.output : '',
43+
),
44+
};
45+
};
3546

3647
const scenarios = [
3748
{
@@ -402,6 +413,16 @@ describe(`OpenAPI ${version}`, () => {
402413
}),
403414
description: 'handles null enums',
404415
},
416+
{
417+
config: createConfig({
418+
input: {
419+
exclude: ['@deprecated'],
420+
path: 'exclude-deprecated.yaml',
421+
},
422+
output: 'exclude-deprecated',
423+
}),
424+
description: 'excludes deprecated fields',
425+
},
405426
{
406427
config: createConfig({
407428
input: 'internal-name-conflict.json',
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
export * from './types.gen';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type Foo = string;
4+
5+
export type PostFooData = {
6+
body: Foo;
7+
path?: never;
8+
query?: never;
9+
url: '/foo';
10+
};
11+
12+
export type PostFooResponses = {
13+
/**
14+
* OK
15+
*/
16+
200: unknown;
17+
};
18+
19+
export type ClientOptions = {
20+
baseUrl: string;
21+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
export * from './types.gen';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type Foo = string;
4+
5+
export type PostFooData = {
6+
body: Foo;
7+
path?: never;
8+
query?: never;
9+
url: '/foo';
10+
};
11+
12+
export type PostFooResponses = {
13+
/**
14+
* OK
15+
*/
16+
200: unknown;
17+
};
18+
19+
export type ClientOptions = {
20+
baseUrl: `${string}://${string}` | (string & {});
21+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
export * from './types.gen';

0 commit comments

Comments
 (0)