Skip to content

PavelPolyakov/fastify-serve-swagger-ui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastify-serve-swagger-ui serves swagger UI for your fastify instance, at the same time allowig you to inject swagger specification of your choice as default speficiation.

install

npm i fastify-serve-swagger-ui

usage

file

const fastify = require("fastify")();
fastify.register(require("fastify-serve-swagger-ui"), {
  // swagger specification which should be exposed
  specification: {
    type: "file",
    path: "./var/examples/example.yaml"
  },
  // path under which swagger-ui will be available
  path: "swagger"
});

const start = async () => {
  try {
    await fastify.listen(3000);

    console.log(`server listening on ${fastify.server.address().port}`);
  } catch (err) {
    console.error(err);
    process.exit(1);
  }
};

start();

Given that ./var/examples/example.yaml is the path which is relative to the root of the project. You can then open http://localhost:3000/swagger/ and see the swagger-ui which shows your specification.

Example: image

url

Another variant is to provide the specification fot the url, you can pass the object like this:

{
	specification: {
		type: "url",
		url: "http://petstore.swagger.io/v2/swagger.json"
	},
	path: 'swagger'
}

Basic working example is located under var/examples/simple.js.

other

fastify-serve-swagger-ui works wunderfully with fastify-blipp, try it out!

About

swagger-ui for fastify

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published