@openapi-ts/express
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@openapi-ts/express

Express implementation for @openapi-ts/backend

Installation

$ npm install @openapi-ts/express

Usage

This module extends @openapi-ts/backend with an Express sub-class of the OpenApi class, and provides bindings between Express request handlers and the OpenApi instance so that incoming requests may be easily routed to the operations registered on the OpenApi instance.

The module exports all the members from @openapi-ts/backend to make for a single clear interface.

Minimal example:

import {app} from 'express';
import {ExpressOpenApi} from '@openapi-ts/express';

const api = new ExpressOpenApi().register({
  definition: 'path/to/open-api.yml',
  operations: {
    async getPet(req, res, params) {
      // return a pet
    }
  }
});

const app = express();
app.use(api.requestHandler());

Credits

Thanks go to @keithbro for suggesting support for Express and providing code as inspiration for the implementation.

Package Sidebar

Install

npm i @openapi-ts/express

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

11.4 kB

Total Files

17

Last publish

Collaborators

  • henhal