Giter VIP home page Giter VIP logo

exegesis-koa's Introduction

exegesis-koa

Build Status Coverage Status Known Vulnerabilities

exegesis

n. An explanation or critical interpretation of a text, especially an API definition document.

-- No dictionary ever

This library implements a Koa middleware for OpenAPI 3.x.

npm install exegesis-koa

Tutorial

Check out the tutorial here.

Usage

const Koa = require('koa')
const path = require('path')
const exegesisKoa = require('exegesis-koa')

async function createServer() {
    // See https://github.com/exegesis-js/exegesis/blob/master/docs/Options.md
    const options = {
        controllers: path.resolve(__dirname, './controllers')
    }
    const exegesisMiddleware = exegesisKoa(path.resolve(__dirname, './openapi.yaml'), options)

    const app = new Koa()

    // If you have any body parsers, this should go before them.
    app.use(async (ctx, next) => {
      try {
        await next()
      } catch (err) {
        ctx.status = 500
        ctx.body = `Internal error: ${err.message}`
      }
    })
    app.use(exegesisMiddleware)
    app.use(async (ctx) => {
      if (ctx.status === 404) {
        ctx.status = 404
      }
    })

    app.listen()
}

Calling exegesiskoa(openApiFile, options) will return a Promise which resolves to a koa middleware.

openApiFile is either a path to your openapi.yaml or openapi.json file, or it can be a JSON object with the contents of your OpenAPI document. This should have the x-exegesis-controller extension defined on any paths you want to be able to access.

options can be anything you can pass to exegesis. At a minimum, you'll probably want to provide options.controllers, a path to where your controller modules can be found. If you have any security requirements defined, you'll also want to pass in some authenticators. To enable response validation, you'll want to provide a validation callback function via onResponseValidationError(). Exegesis's functionality can also be extended using plugins, which run on every request. Plugins let you add functionality like role base authorization, or CORS.

exegesis-koa's People

Contributors

confuser avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kf6kjg

exegesis-koa's Issues

Frostcast Purchase/Revival Inquiry

Hey Confuser!!! You will likely not remember me at all but I was once a moderator on Frostcast back in 2013 for a short while before I slowly decided to branch off into Pandora with Simon(didn't staff there just played.) I am looking to buy Frostcast, or bring back the project. Over the last 8 years, I have remained heavily in the Minecraft scene and helped endless projects reach heights and never felt what Frostcast had given me. So I am here looking to carry on the legacy of that project and bring back the network under the Frostcast.net domain. I have purchased the Org domain so if all else fails I will go on to likely work with that but in reality, it is the .net that holds the crown and the legacy on google and across Minecraft. I would love to talk and if you aren't the owner of the domain see if we can track down who :D please contact me at [email protected]. I will give you a shout on LinkedIn as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.