From b838e1885fe80dee263f6a46644909a900eb3f14 Mon Sep 17 00:00:00 2001 From: Daniel Ludwig Date: Fri, 31 Jul 2020 11:58:43 +0200 Subject: [PATCH] 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 --- CONTRIBUTING.md | 3 +-- docs/contributing.md | 3 +-- .../src/main/resources/typescript-node/api-single.mustache | 5 +++-- .../src/main/resources/typescript-node/models.mustache | 2 +- .../src/main/resources/typescript-node/tsconfig.mustache | 2 ++ .../client/petstore/typescript-node/default/api/petApi.ts | 5 +++-- .../client/petstore/typescript-node/default/api/storeApi.ts | 5 +++-- .../client/petstore/typescript-node/default/api/userApi.ts | 5 +++-- .../client/petstore/typescript-node/default/model/models.ts | 2 +- samples/client/petstore/typescript-node/npm/api/petApi.ts | 5 +++-- samples/client/petstore/typescript-node/npm/api/storeApi.ts | 5 +++-- samples/client/petstore/typescript-node/npm/api/userApi.ts | 5 +++-- samples/client/petstore/typescript-node/npm/model/models.ts | 2 +- samples/client/petstore/typescript-node/npm/tsconfig.json | 2 ++ 14 files changed, 30 insertions(+), 21 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f4daf0ea070..8fedced7329 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -87,8 +87,7 @@ To add test cases (optional) covering the change in the code generator, please r To test the templates, please perform the following: - Update the Petstore sample by running the shell scripts under the `bin` folder. For example, run `./bin/generate-samples.sh . -/bin/configs/python*` to update the Python-related samples under [`samples`](https://github.com/openapitools/openapi-generator/t -ree/master/samples). For Windows, please install [GIT bash](https://gitforwindows.org/). (If you find that there are new files g +/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 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 m time to time. If you've questions or concerns, please open a ticket to start a discussion) - 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`. diff --git a/docs/contributing.md b/docs/contributing.md index 171682dac06..8fcb22b9eab 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -91,8 +91,7 @@ To add test cases (optional) covering the change in the code generator, please r To test the templates, please perform the following: - Update the Petstore sample by running the shell scripts under the `bin` folder. For example, run `./bin/generate-samples.sh . -/bin/configs/python*` to update the Python-related samples under [`samples`](https://github.com/openapitools/openapi-generator/t -ree/master/samples). For Windows, please install [GIT bash](https://gitforwindows.org/). (If you find that there are new files g +/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 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 m time to time. If you've questions or concerns, please open a ticket to start a discussion) - 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`. diff --git a/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache b/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache index d54c5bd341b..e8a6cc5bf36 100644 --- a/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache @@ -1,6 +1,7 @@ {{>licenseInfo}} -import localVarRequest = require('request'); -import http = require('http'); + +import localVarRequest from 'request'; +import http from 'http'; /* tslint:disable:no-unused-locals */ {{#imports}} diff --git a/modules/openapi-generator/src/main/resources/typescript-node/models.mustache b/modules/openapi-generator/src/main/resources/typescript-node/models.mustache index f129eb63e78..41bf1422eab 100644 --- a/modules/openapi-generator/src/main/resources/typescript-node/models.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-node/models.mustache @@ -4,7 +4,7 @@ export * from '{{{ classFilename }}}'; {{/model}} {{/models}} -import localVarRequest = require('request'); +import localVarRequest from 'request'; {{#models}} {{#model}} diff --git a/modules/openapi-generator/src/main/resources/typescript-node/tsconfig.mustache b/modules/openapi-generator/src/main/resources/typescript-node/tsconfig.mustache index 160a99593a7..de78697d22a 100644 --- a/modules/openapi-generator/src/main/resources/typescript-node/tsconfig.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-node/tsconfig.mustache @@ -4,6 +4,8 @@ "noImplicitAny": false, "suppressImplicitAnyIndexErrors": true, "target": "{{#supportsES6}}ES6{{/supportsES6}}{{^supportsES6}}ES5{{/supportsES6}}", + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, "strict": true, "moduleResolution": "node", "removeComments": true, diff --git a/samples/client/petstore/typescript-node/default/api/petApi.ts b/samples/client/petstore/typescript-node/default/api/petApi.ts index 610dafca441..f9bc6cfb93d 100644 --- a/samples/client/petstore/typescript-node/default/api/petApi.ts +++ b/samples/client/petstore/typescript-node/default/api/petApi.ts @@ -10,8 +10,9 @@ * Do not edit the class manually. */ -import localVarRequest = require('request'); -import http = require('http'); + +import localVarRequest from 'request'; +import http from 'http'; /* tslint:disable:no-unused-locals */ import { ApiResponse } from '../model/apiResponse'; diff --git a/samples/client/petstore/typescript-node/default/api/storeApi.ts b/samples/client/petstore/typescript-node/default/api/storeApi.ts index 42ca3f345af..075dc6126fb 100644 --- a/samples/client/petstore/typescript-node/default/api/storeApi.ts +++ b/samples/client/petstore/typescript-node/default/api/storeApi.ts @@ -10,8 +10,9 @@ * Do not edit the class manually. */ -import localVarRequest = require('request'); -import http = require('http'); + +import localVarRequest from 'request'; +import http from 'http'; /* tslint:disable:no-unused-locals */ import { Order } from '../model/order'; diff --git a/samples/client/petstore/typescript-node/default/api/userApi.ts b/samples/client/petstore/typescript-node/default/api/userApi.ts index d22eedd21f8..6122ed4221e 100644 --- a/samples/client/petstore/typescript-node/default/api/userApi.ts +++ b/samples/client/petstore/typescript-node/default/api/userApi.ts @@ -10,8 +10,9 @@ * Do not edit the class manually. */ -import localVarRequest = require('request'); -import http = require('http'); + +import localVarRequest from 'request'; +import http from 'http'; /* tslint:disable:no-unused-locals */ import { User } from '../model/user'; diff --git a/samples/client/petstore/typescript-node/default/model/models.ts b/samples/client/petstore/typescript-node/default/model/models.ts index faf72498f76..1da13addd12 100644 --- a/samples/client/petstore/typescript-node/default/model/models.ts +++ b/samples/client/petstore/typescript-node/default/model/models.ts @@ -5,7 +5,7 @@ export * from './pet'; export * from './tag'; export * from './user'; -import localVarRequest = require('request'); +import localVarRequest from 'request'; import { ApiResponse } from './apiResponse'; import { Category } from './category'; diff --git a/samples/client/petstore/typescript-node/npm/api/petApi.ts b/samples/client/petstore/typescript-node/npm/api/petApi.ts index 610dafca441..f9bc6cfb93d 100644 --- a/samples/client/petstore/typescript-node/npm/api/petApi.ts +++ b/samples/client/petstore/typescript-node/npm/api/petApi.ts @@ -10,8 +10,9 @@ * Do not edit the class manually. */ -import localVarRequest = require('request'); -import http = require('http'); + +import localVarRequest from 'request'; +import http from 'http'; /* tslint:disable:no-unused-locals */ import { ApiResponse } from '../model/apiResponse'; diff --git a/samples/client/petstore/typescript-node/npm/api/storeApi.ts b/samples/client/petstore/typescript-node/npm/api/storeApi.ts index 42ca3f345af..075dc6126fb 100644 --- a/samples/client/petstore/typescript-node/npm/api/storeApi.ts +++ b/samples/client/petstore/typescript-node/npm/api/storeApi.ts @@ -10,8 +10,9 @@ * Do not edit the class manually. */ -import localVarRequest = require('request'); -import http = require('http'); + +import localVarRequest from 'request'; +import http from 'http'; /* tslint:disable:no-unused-locals */ import { Order } from '../model/order'; diff --git a/samples/client/petstore/typescript-node/npm/api/userApi.ts b/samples/client/petstore/typescript-node/npm/api/userApi.ts index d22eedd21f8..6122ed4221e 100644 --- a/samples/client/petstore/typescript-node/npm/api/userApi.ts +++ b/samples/client/petstore/typescript-node/npm/api/userApi.ts @@ -10,8 +10,9 @@ * Do not edit the class manually. */ -import localVarRequest = require('request'); -import http = require('http'); + +import localVarRequest from 'request'; +import http from 'http'; /* tslint:disable:no-unused-locals */ import { User } from '../model/user'; diff --git a/samples/client/petstore/typescript-node/npm/model/models.ts b/samples/client/petstore/typescript-node/npm/model/models.ts index faf72498f76..1da13addd12 100644 --- a/samples/client/petstore/typescript-node/npm/model/models.ts +++ b/samples/client/petstore/typescript-node/npm/model/models.ts @@ -5,7 +5,7 @@ export * from './pet'; export * from './tag'; export * from './user'; -import localVarRequest = require('request'); +import localVarRequest from 'request'; import { ApiResponse } from './apiResponse'; import { Category } from './category'; diff --git a/samples/client/petstore/typescript-node/npm/tsconfig.json b/samples/client/petstore/typescript-node/npm/tsconfig.json index d6a89cb7a45..afce3b7abd4 100644 --- a/samples/client/petstore/typescript-node/npm/tsconfig.json +++ b/samples/client/petstore/typescript-node/npm/tsconfig.json @@ -4,6 +4,8 @@ "noImplicitAny": false, "suppressImplicitAnyIndexErrors": true, "target": "ES5", + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, "strict": true, "moduleResolution": "node", "removeComments": true,