Skip to content

Commit b838e18

Browse files
laubfallwing328
andauthored
typescript-node: clean up require and import (#6947)
* Fix for issue 4656 typescript-node generate invalid require statement instead of import statement * Fixed broken link under testing templates * Result of run generate-samples.sh / typescript-node* * import stmt depending on flag supportsES6 * Update petstore sample for typescript-node * import ... from stmt for http/request module * update samples * update doc Co-authored-by: William Cheng <[email protected]>
1 parent 0f3edb1 commit b838e18

File tree

14 files changed

+30
-21
lines changed

14 files changed

+30
-21
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ To add test cases (optional) covering the change in the code generator, please r
8787
To test the templates, please perform the following:
8888

8989
- Update the Petstore sample by running the shell scripts under the `bin` folder. For example, run `./bin/generate-samples.sh .
90-
/bin/configs/python*` to update the Python-related samples under [`samples`](https://github.com/openapitools/openapi-generator/t
91-
ree/master/samples). For Windows, please install [GIT bash](https://gitforwindows.org/). (If you find that there are new files g
90+
/bin/configs/python*` to update the Python-related samples under [`samples`](https://github.com/openapitools/openapi-generator/tree/master/samples). For Windows, please install [GIT bash](https://gitforwindows.org/). (If you find that there are new files g
9291
enerated or unexpected changes as a result of the update, that's not unusual as the test cases are added to the OpenAPI spec fro
9392
m time to time. If you've questions or concerns, please open a ticket to start a discussion)
9493
- During development it can be helpful to quickly regenerate the samples without recompiling all of openapi-generator, e.g. when you have only updated the mustache templates. This can be done by passing the `-t` parameter: `-t modules/openapi-generator/src/main/resources/python`.

docs/contributing.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ To add test cases (optional) covering the change in the code generator, please r
9191
To test the templates, please perform the following:
9292

9393
- Update the Petstore sample by running the shell scripts under the `bin` folder. For example, run `./bin/generate-samples.sh .
94-
/bin/configs/python*` to update the Python-related samples under [`samples`](https://github.com/openapitools/openapi-generator/t
95-
ree/master/samples). For Windows, please install [GIT bash](https://gitforwindows.org/). (If you find that there are new files g
94+
/bin/configs/python*` to update the Python-related samples under [`samples`](https://github.com/openapitools/openapi-generator/tree/master/samples). For Windows, please install [GIT bash](https://gitforwindows.org/). (If you find that there are new files g
9695
enerated or unexpected changes as a result of the update, that's not unusual as the test cases are added to the OpenAPI spec fro
9796
m time to time. If you've questions or concerns, please open a ticket to start a discussion)
9897
- During development it can be helpful to quickly regenerate the samples without recompiling all of openapi-generator, e.g. when you have only updated the mustache templates. This can be done by passing the `-t` parameter: `-t modules/openapi-generator/src/main/resources/python`.

modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{>licenseInfo}}
2-
import localVarRequest = require('request');
3-
import http = require('http');
2+
3+
import localVarRequest from 'request';
4+
import http from 'http';
45

56
/* tslint:disable:no-unused-locals */
67
{{#imports}}

modules/openapi-generator/src/main/resources/typescript-node/models.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export * from '{{{ classFilename }}}';
44
{{/model}}
55
{{/models}}
66

7-
import localVarRequest = require('request');
7+
import localVarRequest from 'request';
88

99
{{#models}}
1010
{{#model}}

modules/openapi-generator/src/main/resources/typescript-node/tsconfig.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"noImplicitAny": false,
55
"suppressImplicitAnyIndexErrors": true,
66
"target": "{{#supportsES6}}ES6{{/supportsES6}}{{^supportsES6}}ES5{{/supportsES6}}",
7+
"allowSyntheticDefaultImports": true,
8+
"esModuleInterop": true,
79
"strict": true,
810
"moduleResolution": "node",
911
"removeComments": true,

samples/client/petstore/typescript-node/default/api/petApi.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
* Do not edit the class manually.
1111
*/
1212

13-
import localVarRequest = require('request');
14-
import http = require('http');
13+
14+
import localVarRequest from 'request';
15+
import http from 'http';
1516

1617
/* tslint:disable:no-unused-locals */
1718
import { ApiResponse } from '../model/apiResponse';

samples/client/petstore/typescript-node/default/api/storeApi.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
* Do not edit the class manually.
1111
*/
1212

13-
import localVarRequest = require('request');
14-
import http = require('http');
13+
14+
import localVarRequest from 'request';
15+
import http from 'http';
1516

1617
/* tslint:disable:no-unused-locals */
1718
import { Order } from '../model/order';

samples/client/petstore/typescript-node/default/api/userApi.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
* Do not edit the class manually.
1111
*/
1212

13-
import localVarRequest = require('request');
14-
import http = require('http');
13+
14+
import localVarRequest from 'request';
15+
import http from 'http';
1516

1617
/* tslint:disable:no-unused-locals */
1718
import { User } from '../model/user';

samples/client/petstore/typescript-node/default/model/models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export * from './pet';
55
export * from './tag';
66
export * from './user';
77

8-
import localVarRequest = require('request');
8+
import localVarRequest from 'request';
99

1010
import { ApiResponse } from './apiResponse';
1111
import { Category } from './category';

samples/client/petstore/typescript-node/npm/api/petApi.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
* Do not edit the class manually.
1111
*/
1212

13-
import localVarRequest = require('request');
14-
import http = require('http');
13+
14+
import localVarRequest from 'request';
15+
import http from 'http';
1516

1617
/* tslint:disable:no-unused-locals */
1718
import { ApiResponse } from '../model/apiResponse';

samples/client/petstore/typescript-node/npm/api/storeApi.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
* Do not edit the class manually.
1111
*/
1212

13-
import localVarRequest = require('request');
14-
import http = require('http');
13+
14+
import localVarRequest from 'request';
15+
import http from 'http';
1516

1617
/* tslint:disable:no-unused-locals */
1718
import { Order } from '../model/order';

samples/client/petstore/typescript-node/npm/api/userApi.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
* Do not edit the class manually.
1111
*/
1212

13-
import localVarRequest = require('request');
14-
import http = require('http');
13+
14+
import localVarRequest from 'request';
15+
import http from 'http';
1516

1617
/* tslint:disable:no-unused-locals */
1718
import { User } from '../model/user';

samples/client/petstore/typescript-node/npm/model/models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export * from './pet';
55
export * from './tag';
66
export * from './user';
77

8-
import localVarRequest = require('request');
8+
import localVarRequest from 'request';
99

1010
import { ApiResponse } from './apiResponse';
1111
import { Category } from './category';

samples/client/petstore/typescript-node/npm/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"noImplicitAny": false,
55
"suppressImplicitAnyIndexErrors": true,
66
"target": "ES5",
7+
"allowSyntheticDefaultImports": true,
8+
"esModuleInterop": true,
79
"strict": true,
810
"moduleResolution": "node",
911
"removeComments": true,

0 commit comments

Comments
 (0)