Skip to content

Commit 1b071b0

Browse files
authored
Merge pull request #48 from nicolas-chaulet/feat/remove-union-types-flag
feat(parser): remove useUnionTypes flag
2 parents 2e98a0f + 38e018d commit 1b071b0

File tree

105 files changed

+1247
-891
lines changed

Some content is hidden

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

105 files changed

+1247
-891
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
save-exact=true

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ $ openapi --help
5050
-c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch")
5151
--name <value> Custom client class name
5252
--useOptions <value> Use options instead of arguments (default: false)
53-
--useUnionTypes Use union types instead of enums
5453
--exportCore <value> Write core files to disk (default: true)
5554
--exportServices <value> Write services to disk [true, false, regexp] (default: true)
5655
--exportModels <value> Write models to disk [true, false, regexp] (default: true)

bin/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const params = program
1515
.option('-c, --client <value>', 'HTTP client to generate [fetch, xhr, node, axios, angular]', 'fetch')
1616
.option('--name <value>', 'Custom client class name')
1717
.option('--useOptions [value]', 'Use options instead of arguments', false)
18-
.option('--useUnionTypes', 'Use union types instead of enums')
1918
.option('--autoformat', 'Process generated files with autoformatter', false)
2019
.option('--base [value]', 'Manually set base in OpenAPI config instead of inferring from server value')
2120
.option('--exportCore <value>', 'Write core files to disk', true)

bin/index.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ describe('bin', () => {
2323
'--client',
2424
'fetch',
2525
'--useOptions',
26-
'--useUnionTypes',
2726
'--exportCore',
2827
'true',
2928
'--exportServices',

package-lock.json

Lines changed: 166 additions & 147 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@
6060
"docker": "docker build -t eeelenbaas/openapi-typescript-codegen ."
6161
},
6262
"dependencies": {
63-
"@apidevtools/json-schema-ref-parser": "^11.1.0",
64-
"camelcase": "^6.3.0",
65-
"commander": "^11.1.0",
66-
"fs-extra": "^11.2.0",
67-
"handlebars": "^4.7.8"
63+
"@apidevtools/json-schema-ref-parser": "11.5.4",
64+
"camelcase": "6.3.0",
65+
"commander": "11.1.0",
66+
"fs-extra": "11.2.0",
67+
"handlebars": "4.7.8",
68+
"node-fetch": "2.7.0"
6869
},
6970
"devDependencies": {
7071
"@angular-devkit/build-angular": "17.0.9",
@@ -92,7 +93,7 @@
9293
"@types/glob": "8.1.0",
9394
"@types/jest": "29.5.12",
9495
"@types/node": "20.11.17",
95-
"@types/node-fetch": "2.6.10",
96+
"@types/node-fetch": "2.6.11",
9697
"@types/qs": "6.9.11",
9798
"@typescript-eslint/eslint-plugin": "6.21.0",
9899
"@typescript-eslint/parser": "6.21.0",
@@ -109,9 +110,8 @@
109110
"glob": "10.3.10",
110111
"jest": "29.7.0",
111112
"jest-cli": "29.7.0",
112-
"node-fetch": "2.7.0",
113113
"prettier": "3.2.5",
114-
"puppeteer": "21.11.0",
114+
"puppeteer": "22.4.1",
115115
"qs": "6.11.2",
116116
"rimraf": "5.0.5",
117117
"rollup": "4.7.0",

rollup.config.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,24 @@ const handlebarsPlugin = () => ({
3030
knownHelpersOnly: true,
3131
knownHelpers: {
3232
camelCase: true,
33-
containsSpaces: true,
34-
enumerator: true,
33+
debugThis: true,
34+
enumKey: true,
35+
enumName: true,
36+
enumUnionType: true,
37+
enumValue: true,
3538
equals: true,
3639
escapeComment: true,
3740
escapeDescription: true,
38-
escapeEnumName: true,
3941
escapeNewline: true,
4042
exactArray: true,
4143
ifdef: true,
4244
ifOperationDataOptional: true,
45+
inlineEnum: true,
4346
intersection: true,
47+
modelImports: true,
48+
modelUnionType: true,
4449
nameOperationDataType: true,
4550
notEquals: true,
46-
union: true,
4751
useDateType: true,
4852
},
4953
});

src/client/interfaces/Enum.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export interface Enum {
2-
name: string;
3-
value: string;
4-
type: string;
5-
description: string | null;
2+
'x-enum-description'?: string;
3+
'x-enum-varname'?: string;
4+
description?: string;
5+
value: string | number;
66
}

src/client/interfaces/Model.d.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,33 @@ import type { Enum } from './Enum';
22
import type { Schema } from './Schema';
33

44
export interface Model extends Schema {
5-
name: string;
5+
/**
6+
* **Experimental.** Contains list of original refs so they can be used
7+
* to access the schema from anywhere instead of relying on string name.
8+
* This allows us to do things like detect type of ref.
9+
*/
10+
$refs: string[];
11+
base: string;
12+
default?: string;
13+
deprecated?: boolean;
14+
description: string | null;
15+
enum: Enum[];
16+
enums: Model[];
617
export:
7-
| 'reference'
8-
| 'generic'
9-
| 'enum'
18+
| 'all-of'
19+
| 'any-of'
1020
| 'array'
21+
| 'const'
1122
| 'dictionary'
23+
| 'enum'
24+
| 'generic'
1225
| 'interface'
1326
| 'one-of'
14-
| 'any-of'
15-
| 'all-of'
16-
| 'const';
17-
type: string;
18-
base: string;
19-
template: string | null;
20-
link: Model | null;
21-
description: string | null;
22-
deprecated?: boolean;
23-
default?: string;
27+
| 'reference';
2428
imports: string[];
25-
enum: Enum[];
26-
enums: Model[];
29+
link: Model | null;
30+
name: string;
2731
properties: Model[];
32+
template: string | null;
33+
type: string;
2834
}
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import type { Model } from './Model';
22

3-
export interface ModelComposition {
4-
enums: Model[];
5-
export: 'one-of' | 'any-of' | 'all-of';
6-
imports: string[];
7-
properties: Model[];
3+
export interface ModelComposition extends Pick<Model, '$refs' | 'enums' | 'imports' | 'properties'> {
4+
export: Extract<Model['export'], 'all-of' | 'any-of' | 'one-of'>;
85
}

0 commit comments

Comments
 (0)