-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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] add new generator for Axios #892
[TypeScript] add new generator for Axios #892
Conversation
Ping @wing328 |
Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors. Let me know if you need help fixing it. |
cc the technical committee for review @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) |
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.
I can't find differences to the typescript-fetch generator. What is the new feature of this generator?
@@ -0,0 +1,45 @@ | |||
## {{npmName}}@{{npmVersion}} | |||
|
|||
This generator creates TypeScript/JavaScript client that utilizes [Fetch API](https://fetch.spec.whatwg.org/). The generated Node module can be used in the following environments: |
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.
is this correct? shouldn't it be about axios?
@@ -0,0 +1,368 @@ | |||
/// <reference path="./custom.d.ts" /> |
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.
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.
I believe @nicokoenig has made some updates to use axios.
@nicokoenig have you committed those changes to this PR?
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 yet, changes to come. I made the PR on behalf of @wing328 so that he could check for initial mistakes 👍
I pushed some updates... could someone please have a look? |
"build": "tsc --outDir dist/", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"dependencies": { |
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.
Do we need to add axios
dependency (peer, dev) somehow?
e.g. https://github.com/sheaivey/react-axios/blob/master/package.json#L45, https://github.com/sheaivey/react-axios/blob/master/package.json#L50
Disclaimer: I'm no expert in TS/JS
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.
You are right, sorry I missed that.
Commit is already pushed.
"description": "OpenAPI client for {{npmName}}", | ||
"author": "OpenAPI-Generator Contributors", | ||
"keywords": [ | ||
"fetch", |
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.
Minor suggestion: replace "fetch" with "axios"?
2ff3c41
to
ecf2f60
Compare
@wing328 Any updates here? 😺 |
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.
please generate some samples, otherwise it is hard to understand the output.
e.g. like https://github.com/OpenAPITools/openapi-generator/blob/master/bin/typescript-angular-v6-petstore-provided-in-root.sh
@nicokoenig to elaborate on @macjohnny feedback a little bit, here are the scripts/batch files for TypeScript Fetch:
Windows batch file:
Please create something similar to generate the Petstore sample and you can copy the tests from TS Fetch Petstore. If you need any help, please let me know. |
it might also be worth adding some integration test to ensure the generated code does not break in the future. |
{{/hasFormParams}} | ||
{{#bodyParam}} | ||
const needsSerialization = (<any>"{{dataType}}" !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; | ||
localVarRequestOptions.body = needsSerialization ? JSON.stringify({{paramName}} || {}) : ({{paramName}} || ""); |
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.
This needs to go in localVarRequestOptions.data
- there is no body
option in Axios.
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.
Thanks for the hint.
ca156fb
to
0e08315
Compare
@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny please have another look as @nicokoenig has added test cases (petstore integration tests) and updated Travis CI config to run these tests as part of the build. |
If no further feedback, I'll merge this PR into master on Monday so that we can start collecting feedback from TypeScript developers. |
Tweet to promote the new generator: https://twitter.com/oas_generator/status/1041939441109983232 |
* feature: add generator for typescript/axios * feature: add sample scripts and sample code * fix: set request body in data property * feature: add samples and tests for typescript axios client * test: add tests for typescript axios client
* feature: add generator for typescript/axios * feature: add sample scripts and sample code * fix: set request body in data property * feature: add samples and tests for typescript axios client * test: add tests for typescript axios client
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.master
,3.3.x
,4.0.x
. Default:master
.Description of the PR
(details of the change, additional tests that have been done, reference to the issue for tracking, etc)