Skip to content
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

Issue with typescript-jquery generator returned promise type #8383

Open
baol opened this issue Jul 3, 2018 · 2 comments · May be fixed by #8385
Open

Issue with typescript-jquery generator returned promise type #8383

baol opened this issue Jul 3, 2018 · 2 comments · May be fixed by #8385

Comments

@baol
Copy link

baol commented Jul 3, 2018

Description

I was not able to use the typescript-jquery bindings in vscode or compile a simple application using them.

    someApi.someMethod().then( (result) => console.log(result.body));

The generated code looks like:

    let dfd = $.Deferred();
    $.ajax(requestOptions).then(
        (data: models.Operation, textStatus: string, jqXHR: JQueryXHR) =>
            dfd.resolve(jqXHR, data),
        (xhr: JQueryXHR, textStatus: string, errorThrown: string) =>
            dfd.reject(xhr, errorThrown)
    );
    return dfd.promise();

While my new-to-the-topic opinion is that it should look more like:

    let dfd = $.Deferred();
    $.ajax(requestOptions).then(
        (data: models.Operation, textStatus: string, jqXHR: JQueryXHR) =>
            dfd.resolve({ request: jqXHR, body: data }),
        (xhr: JQueryXHR, textStatus: string, errorThrown: string) =>
            dfd.reject({ request: xhr, body: errorThrown})
    );
    return dfd.promise();

Given that the signature of the generated method is:

public someMethod(): JQueryPromise<{ response: JQueryXHR; body: models.Operation;  }>

Not sure about the reject part, but both the compiler and intellisense are happier.

Swagger-codegen version

2.3.1 and 2.4.0-20180627.132127-273

Using jquery 3.1.1, with @types/jquery 3.3.4

Command line used for generation

swagger-codegen generate -l typescript-jquery -i ... -o ...

Note

It may very well be that I'm doing something wrong, in which case I'd suggest to maybe add some examples on how to call the generated code (either in a comment of the generated code, or in a separate example).

@baol baol changed the title typescript-jquery generator returned promise type Issue with typescript-jquery generator returned promise type Jul 4, 2018
@baol
Copy link
Author

baol commented Jul 10, 2018

Hi @macjohnny, I noticed you took care of a few typescript related pr in the past, would you have a look here?

@rahulbpatel
Copy link

What's the word on fixing this in swagger-codegen? Looks like it was already closed in openapi-generator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants