Using a valid swagger JSON I generated a client using the following command:
openapi-generator generate -i the.json -l typescript-node
The resulting code is invalid Typescript and cannot be transpiled without manual intervention:
import Promise = require('bluebird');
The above line is completely redundant in Typescript. There is no requirement to use bluebird as promises are part of the basic node offering.
import { ObjectSerializer, Authentication, HttpBasicAuth, ApiKeyAuth, OAuth, VoidAuth } from '../model/models';
error TS6133: 'HttpBasicAuth' is declared but its value is never read.
error TS6133: 'ApiKeyAuth' is declared but its value is never read.
error TS6133: 'OAuth' is declared but its value is never read.
Apart from the errors themselves, it is concerning that no oauth authentication is included in the authentications property.
Asynchronous methods (those that return a Promise) should be declared as async methods. For example, this:
public calculateLine (calculateLineRequest: CalculateLineRequest) : Promise<{ response: http.ClientResponse; body: CalculateLineResponse; }>
should be
public async calculateLine (calculateLineRequest: CalculateLineRequest) : Promise<{ response: http.ClientResponse; body: CalculateLineResponse; }>
otherwise typescript consumers of the API cannot use await when calling the API method.
3.3.4
I cannot provide this as it a private commercial API
openapi-generator generate -i the.json -l typescript-node
Just generate the code
Drop the reference to bluebird.
Declare asynchronous methods as async
Investigate why there is no oauth authentication
馃憤 Thanks for opening this issue!
馃彿 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
sounds good. would you like to give it a try and fix it?
I have given it a try in a locally cloned repo that I branched off master. However I don't know how you would prefer me to proceed with regard to a PR? Firstly is it master that you want me to branch from or not? I cannot push anything upstream because I am not authorised so do I need to be a contributor?
My change was simply to typescript-node/api-single.mustache
please fork the repository, create a new branch from master and file a PR against master. I will be happy to review your changes
OK
@kpturner this may help: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-submit-a-pr-to-fix-bugs-or-make-enhancements
Pull Requests here: https://github.com/OpenAPITools/openapi-generator/pull/2452
I'm not sure this is the correct place to raise it, but there is another problem too:
error TS2694: Namespace '"http"' has no exported member 'ClientResponse'.
The code looks like this:
public remoteMethod (param: String....) : Promise<{ response: http.ClientResponse; body: Response; }> {
It appears that ClientResponse has been removed since Node 10 (I'm on 11.7.0), using the same version of generator (3.3.4).
A related bug:
https://github.com/OpenAPITools/openapi-generator/issues/1138
EDIT: It appears the " --additional-properties supportsES6=true" flag will generate Node 11 compatible code. Should it be the default perhaps?
EDIT: It appears the " --additional-properties supportsES6=true" flag will generate Node 11 compatible code. Should it be the default perhaps?
Good idea. We can make supportsES6 the default in 4.0.0 release. May I know if you've time to file a PR for this?
I'm sorry @wing328, even though I suspect it's a one-line change, it's very unlikely I would have any time to work on this before July.
resolved in #2452
EDIT: It appears the " --additional-properties supportsES6=true" flag will generate Node 11 compatible code. Should it be the default perhaps?
Good idea. We can make
supportsES6the default in 4.0.0 release. May I know if you've time to file a PR for this?
Just in case anyone comes across this, in version 4.1.1 you still need this flag to produce output compatible with Node v10.
I think it has other issue then ?
I am using 4.1.1 and ended up with this:
import { ApiKeyAuth } from '../model/models';
import { ApiKeyAuth } from '../model/models';
(two times lol)
any idea?
@jaydeep987 can you open a separate issue?
Im still experiencing this issue with typescript-node Namespace '"http"' has no exported member 'ClientResponse'. return new Promise<{ response: http.ClientResponse; body: string; }>((resolve, reject). I am using version generator version 4.2.3 and tsc version 3.6.4.
Edit:
This was fixed by downgrading @types/node to version 8.*
@dsudzy as @adam-ah already mentioned, you just have to add --additional-properties supportsES6=true to your generator command.
Most helpful comment
I'm not sure this is the correct place to raise it, but there is another problem too:
The code looks like this:
It appears that ClientResponse has been removed since Node 10 (I'm on 11.7.0), using the same version of generator (3.3.4).
A related bug:
https://github.com/OpenAPITools/openapi-generator/issues/1138
EDIT: It appears the " --additional-properties supportsES6=true" flag will generate Node 11 compatible code. Should it be the default perhaps?