Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
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)
The npm package swagger-ui-dist receives a total of 2,807,546 weekly downloads. As such, swagger-ui-dist popularity was classified as popular.
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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.