-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[typescript-axios] Add option to add NodeJS imports #10990
Merged
macjohnny
merged 6 commits into
OpenAPITools:master
from
vesse:feature/typescript-axios-add-import-url-option
Dec 24, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
243efed
[typescript-axios] Add new option to generate imports from 'url'
vesse 8529b5f
[typescript-axios] Add withImportUrl support to templates
vesse 5e5ff8e
[typescript-axios] Generate new samples using withImportUrl
vesse c64ced2
[typescript-axios] Add withImportUrl to documentation
vesse f27799c
[typescript-axios] Regenerate docs, build was still ongoing and used …
vesse f7044e2
[typescript-axios] Rename withImportUrl to withNodeImports
vesse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
generatorName: typescript-axios | ||
outputDir: samples/client/petstore/typescript-axios/builds/with-node-imports | ||
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore-with-operations-without-required-params.yaml | ||
templateDir: modules/openapi-generator/src/main/resources/typescript-axios | ||
additionalProperties: | ||
withNodeImports: "true" | ||
multipartFormData: "true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
samples/client/petstore/typescript-axios/builds/with-node-imports/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
wwwroot/*.js | ||
node_modules | ||
typings | ||
dist |
1 change: 1 addition & 0 deletions
1
samples/client/petstore/typescript-axios/builds/with-node-imports/.npmignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm |
23 changes: 23 additions & 0 deletions
23
samples/client/petstore/typescript-axios/builds/with-node-imports/.openapi-generator-ignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# OpenAPI Generator Ignore | ||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
||
# Use this file to prevent files from being overwritten by the generator. | ||
# The patterns follow closely to .gitignore or .dockerignore. | ||
|
||
# As an example, the C# client generator defines ApiClient.cs. | ||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
#ApiClient.cs | ||
|
||
# You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
#foo/*/qux | ||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
#foo/**/qux | ||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
||
# You can also negate patterns with an exclamation (!). | ||
# For example, you can ignore all files in a docs folder with the file extension .md: | ||
#docs/*.md | ||
# Then explicitly reverse the ignore rule for a single file: | ||
#!docs/README.md |
8 changes: 8 additions & 0 deletions
8
samples/client/petstore/typescript-axios/builds/with-node-imports/.openapi-generator/FILES
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.gitignore | ||
.npmignore | ||
api.ts | ||
base.ts | ||
common.ts | ||
configuration.ts | ||
git_push.sh | ||
index.ts |
1 change: 1 addition & 0 deletions
1
samples/client/petstore/typescript-axios/builds/with-node-imports/.openapi-generator/VERSION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5.3.1-SNAPSHOT |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this should have
// @ts-ignore
– it is of course possible to set themultipartFormData
parameter for a spec that does not have any form data endpoints and then this import would be unused (and probably theform-data
dependency is missing too if not needed), but then again is it a user error if they configure to use something that is not needed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my view, it totally is. Or otherwise put - if you declared your need for this code but it's not there (e.g. you want to manually extend the file), would that not be a generation error?
In my humble opinion, neither of
eslint-disable
,tslint:disable
orts-ignore
should be present in this file. All of the unused imports can and should be fixed usingeslint --fix
,prettier --write
or whatever code formatter someone uses. Since this is a programatic change, not a manual one, you can consistently apply it after each generation.That's how I do it. I remove all these comments using
sed
after generating the source code and before formatting. The only warnings I get are related to the use ofany
typings.Besides, tslint has also been deprecated since 2019.
Btw,
typescript-node
has quite a few linting errors, including circular dependencies - yet another reason to deprecate that generator template.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eslint --fix
doesn't fix unused importsand TS itself doesn't have autofix capability (so
noUnusedLocals
compiler setting will simply fail to compile the generated code)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amakhrov I'm using eslint-plugin-unused-imports to remove unused imports.
IMO, the generated code should either be valid, or not disable linting. The latter is especially tricky, since you must support all linting tooling (e.g. there should also be a
.prettierignore
), which to me seems unfeasable.What other code generators do, is lint and/or format the code themselves after generation. That could be an option for JS as well.
But we are diverging from the topic of the PR.