Documentation
    Preparing search index...
    • Template

      Creates a request sender object that can be used to send fake HTTP requests using supertest based on an OpenAPI specification. The openapi types should be generated using the openapi-typescript package.

      Paths - The type representing the paths defined in the OpenAPI specification. Operations - The type representing the operations defined in the OpenAPI specification.

      Type Parameters

      • Paths extends PathsTemplate = never
      • Operations extends OperationsTemplate = never

      Parameters

      • openapiFilePath: Operations extends never ? never : string

        The file path to the OpenAPI specification file.

      • app: Application

        The Express application instance.

      • options: RequestSenderOptions = {}

        Optional configuration options for the request sender.

      Returns Promise<RequestSender<Paths, Operations>>

      A promise that resolves to a RequestSender object.

      import express from 'express';
      import { createRequestSender } from './requestSender';
      import type { paths, operations } from './openapi';

      const app = express();
      const openapiFilePath = './openapi3.yaml';

      const requestSender = await createRequestSender<paths, operations>(openapiFilePath, app);

      // Using operation name
      const response1 = await requestSender.getUsers();

      // Using path and method
      const response2 = await requestSender.sendRequest({
      method: 'get',
      path: '/simple-request'
      });