Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swagger-ui-dist

Package Overview
Dependencies
Maintainers
4
Versions
314
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-ui-dist

[![NPM version](https://badge.fury.io/js/swagger-ui-dist.svg)](http://badge.fury.io/js/swagger-ui-dist)

  • 5.10.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.5M
decreased by-4.74%
Maintainers
4
Weekly downloads
 
Created

What is swagger-ui-dist?

The swagger-ui-dist package is a distribution of Swagger UI's built files. Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API. It allows you to visualize and interact with the API’s resources without having any of the implementation logic in place.

What are swagger-ui-dist's main functionalities?

API Documentation

Serve the Swagger UI as a static site in an Express application, providing a visual documentation for your API.

const swaggerUi = require('swagger-ui-dist');
const express = require('express');
const app = express();

app.use('/api-docs', express.static(swaggerUi.getAbsoluteFSPath()));

app.listen(3000, () => {
  console.log('Swagger UI hosted at http://localhost:3000/api-docs');
});

Customization

Customize the Swagger UI by replacing the default URL with your API's URL before serving the HTML file.

const pathToSwaggerUi = require('swagger-ui-dist').absolutePath();
const http = require('http');
const fs = require('fs');

http.createServer((req, res) => {
  if (req.url === '/api-docs') {
    fs.readFile(`${pathToSwaggerUi}/index.html`, 'utf-8', (err, data) => {
      if (err) {
        res.writeHead(404);
        res.end('Not found');
      } else {
        // Customize HTML before sending it
        const result = data.replace('https://petstore.swagger.io/v2/swagger.json', 'url_to_your_api.json');
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.end(result);
      }
    });
  }
}).listen(8080);

Other packages similar to swagger-ui-dist

FAQs

Package last updated on 14 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