swagger-js
swagger-js copied to clipboard
How to increase timeout on the Swagger Client request
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.