Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
swagger-ui-dist
Advanced tools
[![NPM version](https://badge.fury.io/js/swagger-ui-dist.svg)](http://badge.fury.io/js/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.
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);
ReDoc is an open-source tool that generates API reference documentation from OpenAPI/Swagger definitions. It offers a two-panel, responsive UI and aims for simplicity and readability. Compared to swagger-ui-dist, ReDoc provides a different visual style and may be preferred for its clean, responsive design.
swagger-ui-express is an npm package that allows you to serve auto-generated swagger-ui generated API docs from express, based on a swagger.json file. The package integrates Swagger UI with the Express framework, making it easier to embed within an Express application. It is similar to swagger-ui-dist but tailored specifically for Express.js applications.
swagger-editor-dist is a distribution of Swagger Editor, which is a web-based editor for editing OpenAPI/Swagger specifications. It is similar to swagger-ui-dist in that it is also a Swagger tool, but it focuses on editing and creating specifications rather than displaying them.
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
[![NPM version](https://badge.fury.io/js/swagger-ui-dist.svg)](http://badge.fury.io/js/swagger-ui-dist)
We found that swagger-ui-dist demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.