1.0.1 • Published 2 years ago

fastify-oas-loader v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

fastify-oas-loader

This plugin follows the intention of creating the OpenAPI Scheme first and thereby performing request parameter validation based on it.

This Plugin automatically sets the Fastify-Schema of the RouterOption by reading the pre-written OpenAPI Schema file('yaml', 'json').

After that, we expect Fastify to verify the request parameter based on the set Fastify-Schema.

Installation

npm install fastify-oas-loader

Example

or with ESM syntax:

import fastify from 'fastify';
import oasSchema from 'fastify-oas-loader';

const app = fastify();
app.register(oasSchema, {
  documentPath: 'openapi3.schema.yaml', // relative path to project root dir, required
  ignoreRouters: [
    {
      method: 'GET',
      path: '/health-check',
    },
  ],
});

app.listen(3000);

// If you send request with invalid parameter schema, the server throws schema error

options

nametypedescription
documentPathstringOpenAPI schema file(yaml, json) path, relative to project rootrequired
ignoreRouters{ method: string, path: string }[]You can only register the router described in Schema., but you can alow some routers ignore this ruleoptional
logbooleanWhether to use the log. this plugin use fastify.log.info() & fastify.log.warn()default true