Answer the question
In order to leave comments, you need to log in
How to properly connect Swagger for fastify on node.js?
Good afternoon, please tell me: I'm trying to connect swagger for Rest API on fastify, but nothing happens:
index.ts
import * as SwaggerPlugin from 'fastify-swagger'
const server = fastify ({
logger: true
})
// Документация API
server.register( SwaggerPlugin, require('./config/swagger'))
server.listen (Number.parseInt(process.env.PORT) || 3000, '0.0.0.0', (err, address) => {
if (err) throw err
server.log.info(`Server listening on ${address}`)
server.swagger()
})
exports.options = {
routePrefix: '/doc',
exposeRoute: true,
swagger: {
info: {
title: 'Fastify API',
description: 'Building a blazing fast REST API with Node.js, MongoDB, Fastify and Swagger',
version: '1.0.0'
},
externalDocs: {
url: 'https://swagger.io',
description: 'Find more info here'
},
host: 'localhost:3000',
schemes: ['http'],
consumes: ['application/json'],
produces: ['application/json']
}
}
Answer the question
In order to leave comments, you need to log in
It works for me with the same code
const fastify = require('fastify');
const SwaggerPlugin = require('fastify-swagger');
const server = fastify({
logger: true
});
server.register(SwaggerPlugin, {
routePrefix: '/doc',
exposeRoute: true,
swagger: {
info: {
title: 'Fastify API',
description: 'Building a blazing fast REST API with Node.js, MongoDB, Fastify and Swagger',
version: '1.0.0'
},
externalDocs: {
url: 'https://swagger.io',
description: 'Find more info here'
},
host: 'localhost:3000',
schemes: ['http'],
consumes: ['application/json'],
produces: ['application/json']
}
});
server.listen(Number.parseInt(process.env.PORT) || 3000, '0.0.0.0', (err, address) => {
if (err) throw err;
server.log.info(`Server listening on ${address}`);
server.swagger()
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question