swagger-ui-cli
v0.0.11
Published
This is a CLI tool bundle your openapi documentation or serve for live editing.
Readme
Swagger UI CLI
This CLI tool is designed to serve and live-reload an OpenAPI specification file during development, and also to build a static HTML page from your OpenAPI spec file.
Usage
Build
This command will build a static HTML page from your OpenAPI specification file.
swagger-ui-cli build <openapi-file | openapi-url>Options
--output: Output folder name. Default isdist.--multiFileBuild: Should output multiple files instead of single index.html. Default isfalse.--config: Path to the configuration file, there you can configure the swagger-ui. Default isswagger-ui.config.js.
Serve
This command will open a live reloading server, if you change your config it will change the page.
swagger-ui-cli serve <openapi-file | openapi-url>Options
--port: The port to serve the Swagger UI on. Default is8000.--domain: The domain to serve the Swagger UI on. Default islocalhost.--config: Path to the configuration file, there you can configure the swagger-ui. Default isswagger-ui.config.js.--serverConfig: Path to the server configuration file, there you can configure the dev server. Default isswagger-ui.server-config.js.
swagger-ui.config.js
/** @type {import('swagger-ui-cli').ClientConfig} */
const config = {
// For more please visit the official site: https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/usage/configuration.md
docExpansion: 'none',
deepLinking: true,
displayOperationId: true,
defaultModelsExpandDepth: -1,
showExtensions: true,
showCommonExtensions: true,
filter: true,
onComplete: () => console.log('swagger can run'),
};
export default config;swagger-ui.server-config.js
/** @type {import('swagger-ui-cli').ServerConfig} */
const config = {
// Under the hood there is a simple vite server running, so you can use any vite server options here. https://vite.dev/config/server-options
server: {
port: 1234,
},
};
export default config;