OAS 3.x to Fastify routes automation


Keywords
oas, fastify, node, openapi
License
MIT
Install
npm install oas-fastify@1.3.6

Documentation

OAS to Fastify Plugin

OAS 3.x to Fastify routes automation

license release super linter test semantic

Usage

const fastify = require('fastify')()
const spec = require('./petstore.json')

// your handler object properties map to the OAS "operationId"
const handler = {
  listPets: () => { ... }
  createPets: () => { ... }
  showPetById: () => { ... }
}

fastify.register(require('oas-fastify'), { spec, handler }) 

Options

The plugin accepts an options object with the following properties:

  • spec: a valid OpenAPI Specification JSON object
  • handler: an object with properties that map to the spec's operationId names, with the values as functions that will handle the request
Example
const spec = {
  "paths": {
    "/pets": {
      "get": {
        "operationId": "listPets",
        ...
      }
    }
  }
}

const handler = {
  listPets: function (request, reply, fastify) {
    // fastify instance passed in for convenience

    reply.send({ hello: 'world' })
  }
}

Author: Ahmad Nassri • Twitter: @AhmadNassri