3.1.0 • Published 8 months ago

oas-fastify v3.1.0

Weekly downloads
150
License
MIT
Repository
github
Last release
8 months ago

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 }) 

Yaml Support?

using js-yaml
const yaml = require('js-yaml')
const fs   = require('fs')

const spec = yaml.safeLoad(fs.readFileSync('openapi.yml', 'utf8'))


fastify.register(require('oas-fastify'), { spec, handler }) 
using apidevtools/swagger-cli
npx apidevtools/swagger-cli bundle spec/openapi.yml --outfile spec.json

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

3.0.4

8 months ago

3.1.0

8 months ago

3.0.3

1 year ago

3.0.2

1 year ago

3.0.1

2 years ago

2.0.1

2 years ago

3.0.0

2 years ago

1.4.0

3 years ago

1.3.14

3 years ago

2.0.0

3 years ago

1.3.13

3 years ago

1.3.12

3 years ago

1.3.11

3 years ago

1.3.10

3 years ago

1.3.9

4 years ago

1.3.8

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago