Socket
Socket
Sign inDemoInstall

@fastify/swagger-ui

Package Overview
Dependencies
Maintainers
18
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/swagger-ui

Serve Swagger-ui for Fastify


Version published
Maintainers
18
Created

What is @fastify/swagger-ui?

@fastify/swagger-ui is a Fastify plugin that serves an interactive Swagger UI for your Fastify application. It allows you to visualize and interact with the API's resources without having to manually create documentation.

What are @fastify/swagger-ui's main functionalities?

Serve Swagger UI

This feature allows you to serve a Swagger UI for your Fastify application. The code sample demonstrates how to set up the Swagger UI with a custom route prefix and configuration options.

const fastify = require('fastify')();
const swaggerUi = require('@fastify/swagger-ui');

fastify.register(require('@fastify/swagger'), {
  routePrefix: '/documentation',
  swagger: {
    info: {
      title: 'Test API',
      description: 'Testing the Fastify swagger API',
      version: '0.1.0'
    },
    host: 'localhost:3000',
    schemes: ['http'],
    consumes: ['application/json'],
    produces: ['application/json']
  },
  exposeRoute: true
});

fastify.register(swaggerUi, {
  routePrefix: '/docs',
  uiConfig: {
    docExpansion: 'full',
    deepLinking: false
  },
  staticCSP: true,
  transformStaticCSP: (header) => header
});

fastify.listen(3000, err => {
  if (err) throw err;
  console.log('Server listening on http://localhost:3000');
});

Custom UI Configuration

This feature allows you to customize the Swagger UI configuration. The code sample shows how to set up the Swagger UI with custom UI settings such as `docExpansion` and `deepLinking`.

const fastify = require('fastify')();
const swaggerUi = require('@fastify/swagger-ui');

fastify.register(require('@fastify/swagger'), {
  routePrefix: '/documentation',
  swagger: {
    info: {
      title: 'Test API',
      description: 'Testing the Fastify swagger API',
      version: '0.1.0'
    },
    host: 'localhost:3000',
    schemes: ['http'],
    consumes: ['application/json'],
    produces: ['application/json']
  },
  exposeRoute: true
});

fastify.register(swaggerUi, {
  routePrefix: '/docs',
  uiConfig: {
    docExpansion: 'list',
    deepLinking: true
  },
  staticCSP: true,
  transformStaticCSP: (header) => header
});

fastify.listen(3000, err => {
  if (err) throw err;
  console.log('Server listening on http://localhost:3000');
});

Other packages similar to @fastify/swagger-ui

Keywords

FAQs

Package last updated on 06 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc