Skip to content

Latest commit

 

History

History
84 lines (56 loc) · 3.4 KB

README.md

File metadata and controls

84 lines (56 loc) · 3.4 KB

bautajs-fastify

A Fastify plugin for Bauta.js.

How to install

  npm install @axa/bautajs-fastify

Usage

const { bautajsFastify } = require('@axa/fastify');
const fastify = require('fastify')();
const apiDefinition = require('../../api-definition.json');

fastify.register(bautajsFastify, {
  apiDefinition,
  resolversPath: './glob-path-to-your-resolvers/*.js',
  staticConfig: {
    someVar: 2
  }
});

fastify.listen(3000, err => {
  if (err) throw err;
  fastify.log.info('Server listening on localhost:', fastify.server.address().port);
});

Features

### Fastify included plugins

By default the following plugins are included on the fastify instance

  • @fastify/swagger - Automatic swagger documentation exposed through the ${prefix}/explorer path.

Serialization

Fastify response serialization is enabled by default if a response schema is provided, so this means that missing properties from the schema will not be returned on the response. Although, this behaviour can be disabled by the setting strictResponseSerialization set to false.

Validation

Request validation

Fastify has an out-of-the-box request validation, since this validation takes place first, any error in the schema validation will be generated by fastify and not by bautajs-core. Therefore, even if you disable the validation of the request using the bautajs-core methods, the fastify validation will take place anyway.

Response validation

The response validation of bautajs-fastify is related to the flag strictResponseSerialization. If this is enabled (is the default behaviour), the fastify response validation will be used.

This happens because the response schema is used to create the fastify route related to the OpenAPI operation identifier. Since this validation takes place first, any error in the schema validation will be generated by fastify and not by bautajs-core.

If you want to use the validation mechanism of bautajs-core (see Bauta.js validation, you must disable the strictResponseSerialization flag.

Legal Notice

Copyright (c) AXA Group. All rights reserved. Licensed under the (MIT / Apache 2.0) License.

Third party dependencies licenses

Production

Development

Third party dependencies licenses

Production

Development