1.1.2 • Published 2 months ago
@sigiljs-community/swagger-ui-plugin v1.1.2
Sigil SwaggerUI Plugin
Generates and serves Swagger UI at a configurable endpoint
This plugin depends on @sigiljs-community/openapi-plugin
Installation
npm install @sigiljs-community/swagger-ui-plugin
# or
yarn add @sigiljs-community/swagger-ui-plugin
Usage
Import and register the plugin
import { Sigil } from "@sigiljs/sigil"
import { SwaggerUiPlugin, OpenApiPlugin } from "@sigiljs-community/swagger-ui-plugin"
const app = new Sigil()
// In this case, SwaggerUiPlugin depends on the
// OpenApiPlugin, so we need to define it
// before SwaggerUiPlugin
// Read more about OpenApiPlugin configuration
// at the https://github.com/sigiljs-community/openapi-plugin
app.addPlugin(OpenApiPlugin)
// Register the OpenAPI plugin with optional settings
app.addPlugin(SwaggerUiPlugin, {
path: "/docs/" // optional, default is /docs/
// Other optional configuration
})
Define your routes and schemas
// Example route with validation
import { seal } from "@sigiljs/sigil"
const schema = app.defineSchema({ id: seal.string.optional })
app.route("/users")
.query(...schema)
.get((req, res) => res.response({ users: [] }))
Serve and view the spec
Start your server and navigate to http://localhost:3000/docs
// Start server
app.listen(3000)
Congrats! Now you have an autogenerated documentation for your application
License
You can copy and paste the MIT license summary from below.
MIT License
Copyright (c) 2022 Kurai Foundation
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.