Skip to content

"securityWorker" is only used if "secure" option is specified on each request #212

Closed
@dkamyshov

Description

@dkamyshov

Hi! Thanks for the great package.

This seems to be a Fetch API variation of another issue - #192.

Here is what the request method looks like after generating the API with the following parameters:

$ yarn swagger-typescript-api -p ./source.json -o . -n result.ts
class Api {
  // ...

  public request = async <T = any, E = any>({
    body,
    secure,
    // ...
    ...params
  }: FullRequestParams): Promise<HttpResponse<T, E>> => {
    // the "secure" option from this.baseApiParams is not used here
    const secureParams =
      (secure &&
        this.securityWorker &&
        (await this.securityWorker(this.securityData))) ||
      {};

    const requestParams = this.mergeRequestParams(params, secureParams);

    // ...
  };
}

So, basically, when the Fetch API is used, there is no way to make use of securityWorker other than specifying secure on each request. With axios this is solved trivially with interceptors, but I'd like to continue using the Fetch API.

Here is a simple reproduction of the issue (v7.0.0, just run $ yarn): https://github.com/dkamyshov/swagger-typescript-api-bug-repro

swagger-typescript-api 6.4.2, 7.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions