Skip to content

[BUG][typescript-inversify] Type mismatch between service model and HttpClient requirement #3618

Closed

Description

@siada

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

When using typescript in strict mode, the code won't compile if your spec has an optional requestBody because the HttpClient defines body as {} which means 'any except null or undefined'

openapi-generator version

4.1.0

Steps to reproduce

Generated service method:

    public apiAccountLoginPost(loginViewModel?: LoginViewModel, observe?: 'body', headers?: Headers): Promise<LoginViewModelResult>;
    public apiAccountLoginPost(loginViewModel?: LoginViewModel, observe?: 'response', headers?: Headers): Promise<HttpResponse<LoginViewModelResult>>;
    public apiAccountLoginPost(loginViewModel?: LoginViewModel, observe: any = 'body', headers: Headers = {}): Promise<any> {

HttpClient:

    post(url: string, body: {}|FormData, headers?: Headers): Observable<HttpResponse> {
        return this.performNetworkCall(url, "POST", this.getJsonBody(body), this.addJsonHeaders(headers));
    }

Error:

image

Related issues/PRs

#3607

Suggest a fix

I believe changing the {} to any in the HttpClient will resolve this, however I don't know enough about typescript to understand the impact this may have

I'm happy to organise the PR for this if you agree with this change

Activity

  1. auto-labeler commented on Aug 12, 2019

    @auto-labeler

    👍 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.

  2. macjohnny commented on Aug 12, 2019

    @macjohnny
    Member
  3. macjohnny commented on Aug 12, 2019

    @macjohnny
    Member

    @gualtierim what is your opinion?

  4. siada commented on Aug 12, 2019

    @siada
    ContributorAuthor

    For handling the undefined/null values should getJsonBody return null, empty string, or {} ?

  5. macjohnny commented on Aug 12, 2019

    @macjohnny
    Member

    For handling the undefined/null values should getJsonBody return null, empty string, or {} ?

    good question, I guess undefined ?

  6. gualtierim commented on Aug 12, 2019

    @gualtierim
    Contributor

    I agree to change the signature of httpClient with Object|FormData. getJsonBody should return undefined, I will try it the next week

  7. deluksic commented on Aug 20, 2019

    @deluksic

    Also, addJsonHeaders's headers parameter should be optional.

  8. siada commented on Aug 21, 2019

    @siada
    ContributorAuthor

    @deluksic I already fixed that in PR #3607 this issue has been opened as a discussion from that

  9. siada commented on Aug 30, 2019

    @siada
    ContributorAuthor

    @gualtierim Did you manage to get around to trying the solution out yet?

  10. added a commit that references this issue on Sep 12, 2019
    82f00f2
  11. added a commit that references this issue on Sep 13, 2019
    f15f814
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions