Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

exegesis-express

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exegesis-express

Express middleware to handle OpenAPI 3.x.

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is exegesis-express?

exegesis-express is an npm package that provides a framework for building APIs using OpenAPI (formerly known as Swagger) specifications. It integrates with Express.js to allow developers to define their API endpoints, request/response validation, and middleware based on OpenAPI definitions.

What are exegesis-express's main functionalities?

API Endpoint Definition

This code demonstrates how to set up an Express server with exegesis-express middleware to handle API endpoints defined in an OpenAPI specification file.

const express = require('express');
const exegesisExpress = require('exegesis-express');
const path = require('path');

async function createServer() {
  const app = express();

  const options = {
    controllers: path.resolve(__dirname, './controllers'),
  };

  const exegesisMiddleware = await exegesisExpress.middleware(path.resolve(__dirname, './openapi.yaml'), options);

  app.use(exegesisMiddleware);

  app.use((err, req, res, next) => {
    res.status(err.status || 500).json({ message: err.message });
  });

  return app;
}

createServer().then(app => {
  app.listen(3000, () => {
    console.log('Listening on port 3000');
  });
}).catch(err => {
  console.error(err.stack);
  process.exit(1);
});

Request/Response Validation

This code sample shows how to enable request and response validation in an Express server using exegesis-express. The `validateResponses` option ensures that responses conform to the OpenAPI specification.

const express = require('express');
const exegesisExpress = require('exegesis-express');
const path = require('path');

async function createServer() {
  const app = express();

  const options = {
    controllers: path.resolve(__dirname, './controllers'),
    validateResponses: true, // Enable response validation
  };

  const exegesisMiddleware = await exegesisExpress.middleware(path.resolve(__dirname, './openapi.yaml'), options);

  app.use(exegesisMiddleware);

  app.use((err, req, res, next) => {
    res.status(err.status || 500).json({ message: err.message });
  });

  return app;
}

createServer().then(app => {
  app.listen(3000, () => {
    console.log('Listening on port 3000');
  });
}).catch(err => {
  console.error(err.stack);
  process.exit(1);
});

Custom Middleware Integration

This code demonstrates how to integrate custom middleware into an Express server that uses exegesis-express. The custom middleware logs a message for each request.

const express = require('express');
const exegesisExpress = require('exegesis-express');
const path = require('path');

async function createServer() {
  const app = express();

  const options = {
    controllers: path.resolve(__dirname, './controllers'),
  };

  const exegesisMiddleware = await exegesisExpress.middleware(path.resolve(__dirname, './openapi.yaml'), options);

  app.use(exegesisMiddleware);

  // Custom middleware
  app.use((req, res, next) => {
    console.log('Custom middleware executed');
    next();
  });

  app.use((err, req, res, next) => {
    res.status(err.status || 500).json({ message: err.message });
  });

  return app;
}

createServer().then(app => {
  app.listen(3000, () => {
    console.log('Listening on port 3000');
  });
}).catch(err => {
  console.error(err.stack);
  process.exit(1);
});

Other packages similar to exegesis-express

Keywords

FAQs

Package last updated on 01 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc