Socket
Socket
Sign inDemoInstall

swagger-ui-dist

Package Overview
Dependencies
0
Maintainers
4
Versions
298
Alerts
File Explorer

Advanced tools

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)


Version published
Weekly downloads
3.1M
increased by1.12%
Maintainers
4
Created
Weekly downloads
 

Package description

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

Readme

Source

Swagger UI Dist

NPM version

API

This module, swagger-ui-dist, exposes Swagger-UI's entire dist folder as a dependency-free npm module. Use swagger-ui instead, if you'd like to have npm install dependencies for you.

SwaggerUIBundle and SwaggerUIStandalonePreset can be imported:

  import { SwaggerUIBundle, SwaggerUIStandalonePreset } from "swagger-ui-dist"

To get an absolute path to this directory for static file serving, use the exported getAbsoluteFSPath method:

const swaggerUiAssetPath = require("swagger-ui-dist").getAbsoluteFSPath()

// then instantiate server that serves files from the swaggerUiAssetPath

For anything else, check the Swagger-UI repository.

FAQs

Last updated on 22 Apr 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc