Skip to content

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

@siada

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

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