A Fastify plugin for Bauta.js.
npm install @axa/bautajs-fastify
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);
});
### 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.
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.
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.
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.
Copyright (c) AXA Group. All rights reserved. Licensed under the (MIT / Apache 2.0) License.
- @axa/[email protected] - MIT*
- [email protected] - MIT
- @fastify/[email protected] - MIT
- [email protected] - MIT
- [email protected] - MIT
- @axa/[email protected] - MIT*
- @axa/[email protected] - MIT*
- [email protected] - MIT
- @fastify/[email protected] - MIT
- [email protected] - MIT
- @axa/[email protected] - MIT*