Skip to content

Commit 7e18d95

Browse files
authored
Merge branch 'master' into feature/optionalDataTypeChange
2 parents 595a164 + 9ed2870 commit 7e18d95

File tree

145 files changed

+2750
-2367
lines changed

Some content is hidden

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

145 files changed

+2750
-2367
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"@typescript-eslint/explicit-module-boundary-types": 0,
2525
"sort-imports": "off",
2626
"import/order": "off",
27-
"simple-import-sort/sort": "error",
27+
"simple-import-sort/imports": "error",
28+
"simple-import-sort/exports": "error",
2829
"prettier/prettier": ["error"]
2930
}
3031
}

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ The OpenAPI spec allows you to define [enums](https://swagger.io/docs/specificat
130130
data model. By default, we convert these enums definitions to [TypeScript enums](https://www.typescriptlang.org/docs/handbook/enums.html).
131131
However, these enums are merged inside the namespace of the model, this is unsupported by Babel, [see docs](https://babeljs.io/docs/en/babel-plugin-transform-typescript#impartial-namespace-support).
132132
Because we also want to support projects that use Babel [@babel/plugin-transform-typescript](https://babeljs.io/docs/en/babel-plugin-transform-typescript),
133-
we offer the flag `--useOptions` to generate [union types](https://www.typescriptlang.org/docs/handbook/unions-and-intersections.html#union-types)
133+
we offer the flag `--useUnionTypes` to generate [union types](https://www.typescriptlang.org/docs/handbook/unions-and-intersections.html#union-types)
134134
instead of the traditional enums. The difference can be seen below:
135135

136136
**Enums:**
@@ -441,6 +441,16 @@ npm install node-fetch --save-dev
441441
npm install form-data --save-dev
442442
```
443443

444+
In order to compile the project and resolve the imports, you will need to enable the `allowSyntheticDefaultImports`
445+
in your `tsconfig.json` file.
446+
447+
```json
448+
{
449+
"allowSyntheticDefaultImports": true
450+
}
451+
```
452+
453+
444454
[npm-url]: https://npmjs.org/package/openapi-typescript-codegen
445455
[npm-image]: https://img.shields.io/npm/v/openapi-typescript-codegen.svg
446456
[license-url]: LICENSE

bin/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ program
2020
.option('--exportModels <value>', 'Write models to disk', true)
2121
.option('--exportSchemas <value>', 'Write schemas to disk', false)
2222
.option('--useDateType', 'Output Date instead of string for the format "date-time" in the models')
23+
.option('--request <value>', 'Path to custom request file')
2324
.parse(process.argv);
2425

2526
const OpenAPI = require(path.resolve(__dirname, '../dist/index.js'));
@@ -36,6 +37,7 @@ if (OpenAPI) {
3637
exportModels: JSON.parse(program.exportModels) === true,
3738
exportSchemas: JSON.parse(program.exportSchemas) === true,
3839
useDateType: program.useDateType,
40+
request: program.request,
3941
})
4042
.then(() => {
4143
process.exit(0);

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
module.exports = {
24
projects: [
35
{
@@ -7,6 +9,7 @@ module.exports = {
79
'<rootDir>/src/**/*.spec.ts',
810
'<rootDir>/test/index.spec.js',
911
],
12+
moduleFileExtensions: ['js', 'ts', 'd.ts'],
1013
moduleNameMapper: {
1114
'\\.hbs$': '<rootDir>/src/templates/__mocks__/index.js',
1215
},

logo.png

-26.7 KB
Binary file not shown.

package.json

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "openapi-typescript-codegen",
3-
"version": "0.5.3",
4-
"description": "NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification.",
3+
"version": "0.7.2",
4+
"description": "Library that generates Typescript clients based on the OpenAPI specification.",
55
"author": "Ferdi Koomen",
66
"homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen",
77
"repository": {
@@ -19,7 +19,6 @@
1919
"generator",
2020
"client",
2121
"typescript",
22-
"javascript",
2322
"yaml",
2423
"json",
2524
"fetch",
@@ -62,47 +61,45 @@
6261
"codecov": "codecov --token=66c30c23-8954-4892-bef9-fbaed0a2e42b"
6362
},
6463
"dependencies": {
65-
"camelcase": "6.1.0",
66-
"commander": "6.2.0",
67-
"handlebars": "4.7.6",
68-
"js-yaml": "3.14.0",
69-
"mkdirp": "1.0.4",
70-
"path": "0.12.7",
71-
"rimraf": "3.0.2"
64+
"camelcase": "^6.2.0",
65+
"commander": "^6.2.0",
66+
"handlebars": "^4.7.6",
67+
"js-yaml": "^3.14.0",
68+
"mkdirp": "^1.0.4",
69+
"rimraf": "^3.0.2"
7270
},
7371
"devDependencies": {
74-
"@babel/cli": "7.12.1",
75-
"@babel/core": "7.11.6",
76-
"@babel/preset-env": "7.11.5",
77-
"@babel/preset-typescript": "7.10.4",
78-
"@rollup/plugin-commonjs": "15.1.0",
79-
"@rollup/plugin-node-resolve": "9.0.0",
80-
"@types/express": "4.17.8",
81-
"@types/jest": "26.0.14",
72+
"@babel/cli": "7.12.10",
73+
"@babel/core": "7.12.9",
74+
"@babel/preset-env": "7.12.10",
75+
"@babel/preset-typescript": "7.12.7",
76+
"@rollup/plugin-commonjs": "17.0.0",
77+
"@rollup/plugin-node-resolve": "11.0.0",
78+
"@types/express": "4.17.9",
79+
"@types/jest": "26.0.19",
8280
"@types/js-yaml": "3.12.5",
83-
"@types/node": "14.11.8",
81+
"@types/node": "14.14.13",
8482
"@types/node-fetch": "2.5.7",
85-
"@typescript-eslint/eslint-plugin": "4.4.1",
86-
"@typescript-eslint/parser": "4.6.0",
87-
"codecov": "3.8.0",
88-
"eslint": "7.11.0",
89-
"eslint-config-prettier": "6.12.0",
90-
"eslint-plugin-prettier": "3.1.4",
91-
"eslint-plugin-simple-import-sort": "5.0.3",
83+
"@types/qs": "6.9.4",
84+
"@typescript-eslint/eslint-plugin": "4.9.1",
85+
"@typescript-eslint/parser": "4.9.1",
86+
"codecov": "3.8.1",
87+
"eslint": "7.15.0",
88+
"eslint-config-prettier": "7.0.0",
89+
"eslint-plugin-prettier": "3.3.0",
90+
"eslint-plugin-simple-import-sort": "7.0.0",
9291
"express": "4.17.1",
9392
"form-data": "3.0.0",
9493
"glob": "7.1.6",
95-
"jest": "26.5.3",
96-
"jest-cli": "26.5.3",
94+
"jest": "26.6.3",
95+
"jest-cli": "26.6.3",
9796
"node-fetch": "2.6.1",
98-
"prettier": "2.1.2",
99-
"puppeteer": "5.4.0",
100-
"rollup": "2.29.0",
97+
"prettier": "2.2.1",
98+
"puppeteer": "5.5.0",
99+
"qs": "6.9.4",
100+
"rollup": "2.34.2",
101101
"rollup-plugin-terser": "7.0.2",
102-
"rollup-plugin-typescript2": "0.28.0",
103-
"typescript": "4.0.3"
104-
},
105-
"resolutions": {
106-
"terser": "5.3.5"
102+
"rollup-plugin-typescript2": "0.29.0",
103+
"typescript": "4.1.3"
107104
}
108105
}

rollup.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const handlebarsPlugin = () => ({
3434
knownHelpers: {
3535
equals: true,
3636
notEquals: true,
37+
containsSpaces: true,
38+
union: true,
3739
},
3840
});
3941
return `export default ${templateSpec};`;
@@ -65,6 +67,7 @@ module.exports = {
6567
'fs',
6668
'os',
6769
'util',
70+
'path',
6871
'http',
6972
'https',
7073
'handlebars/runtime',

src/HttpClient.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum HttpClient {
2+
FETCH = 'fetch',
3+
XHR = 'xhr',
4+
NODE = 'node',
5+
}

src/client/interfaces/Model.d.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@ import type { Schema } from './Schema';
33

44
export interface Model extends Schema {
55
name: string;
6-
export: 'reference' | 'generic' | 'enum' | 'array' | 'dictionary' | 'interface';
6+
export: 'reference' | 'generic' | 'enum' | 'array' | 'dictionary' | 'interface' | 'one-of' | 'any-of' | 'all-of';
77
type: string;
88
base: string;
99
template: string | null;
1010
link: Model | null;
1111
description: string | null;
1212
default?: string;
1313
imports: string[];
14-
extends: string[];
1514
enum: Enum[];
1615
enums: Model[];
1716
properties: Model[];
18-
extendedFrom?: string[];
19-
extendedBy?: string[];
2017
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { Model } from './Model';
2+
3+
export interface ModelComposition {
4+
type: 'one-of' | 'any-of' | 'all-of';
5+
imports: string[];
6+
enums: Model[];
7+
properties: Model[];
8+
}

0 commit comments

Comments
 (0)