Skip to content

typescript-node: clean up require and import #6947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{{>licenseInfo}}

{{#supportsES6}}
import localVarRequest from 'request';
import http from 'http';
{{/supportsES6}}
{{^supportsES6}}
import localVarRequest = require('request');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import var = require does not make much sense to me. This should be probably const localVarRequest = require('request').

Or did I oversee something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the other parts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah thats right, i'll fix it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting some typescript errors with const http = require. These are "TS2503: Cannot find namespace 'http'." and "error TS4055: Return type of public method from exported class has or is using private name 'http'.". As described here: https://stackoverflow.com/questions/31173738/typescript-getting-error-ts2304-cannot-find-name-require there are some ways to make this work, but to be honest i don't see a reason why to make a difference at this point. All other modules are imported with the "import .. from" stmt independent of the ES6 flag. So i removed the switch and changed the tsconfig to make the imports http/request work. What do you think about this solution?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For TypeScript to use these you need the types for the Nodejs internal ones. Basically @types/node.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current solution should be fine.

import http = require('http');
{{/supportsES6}}

/* tslint:disable:no-unused-locals */
{{#imports}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ export * from '{{{ classFilename }}}';
{{/model}}
{{/models}}

{{#supportsES6}}
import localVarRequest from 'request';
{{/supportsES6}}
{{^supportsES6}}
import localVarRequest = require('request');
{{/supportsES6}}

{{#models}}
{{#model}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ api/petApi.ts
api/storeApi.ts
api/userApi.ts
git_push.sh
model/./apiResponse.ts
model/./category.ts
model/./order.ts
model/./pet.ts
model/./tag.ts
model/./user.ts
model/apiResponse.ts
model/category.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Do not edit the class manually.
*/


import localVarRequest = require('request');
import http = require('http');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Do not edit the class manually.
*/


import localVarRequest = require('request');
import http = require('http');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Do not edit the class manually.
*/


import localVarRequest = require('request');
import http = require('http');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ api/petApi.ts
api/storeApi.ts
api/userApi.ts
git_push.sh
model/./apiResponse.ts
model/./category.ts
model/./order.ts
model/./pet.ts
model/./tag.ts
model/./user.ts
model/apiResponse.ts
model/category.ts
model/order.ts
model/pet.ts
model/tag.ts
model/user.ts
model/models.ts
package.json
tsconfig.json
1 change: 1 addition & 0 deletions samples/client/petstore/typescript-node/npm/api/petApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Do not edit the class manually.
*/


import localVarRequest = require('request');
import http = require('http');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Do not edit the class manually.
*/


import localVarRequest = require('request');
import http = require('http');

Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/typescript-node/npm/api/userApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Do not edit the class manually.
*/


import localVarRequest = require('request');
import http = require('http');

Expand Down