swagger-js icon indicating copy to clipboard operation
swagger-js copied to clipboard

How to increase timeout on the Swagger Client request

Open virgiawan opened this issue 1 year ago • 0 comments

How do I increase timeout for my request ? Let say I want to make my request's timeout to 5 minutes.

Are there any configs or setup for that ?

  • OS: macOS
  • Environment: Node.js 14.19.1
  • Method of installation: yarn
  • Swagger-Client version: "swagger-client": "^3.27.0",
  • Swagger/OpenAPI version: Swagger 2.0

I tried like this below, but it seems not working.

Swagger-Client usage:

import SwaggerClient from 'swagger-client';
import includes from 'lodash/includes';

export const createSwaggerOpenAPI2 = async (spec) => {
  const { url, data: strPojoSpec, operationIds } = spec;
  const pojoSpec = JSON.parse(strPojoSpec);

  const requestInterceptor = (request) => {
    request.timeout = 300000;
    return request;
  };
  const client = await new SwaggerClient({
    url,
    timeout: 300000,
    requestInterceptor,
  });

  return {
    client,
    getSpec: () => {
      return spec;
    },
    execute: async (operationId, parameters) => {
      if (!includes(operationIds, operationId)) {
        throw new Error(`Can not found operationId on the database`);
      }

      let requestObject = {
        spec: pojoSpec,
        operationId,
        parameters,
      };

      return client.execute(requestObject);
    },
  };
};

Thanks in advance.

virgiawan avatar Jun 06 '24 10:06 virgiawan