Swagger

Plumier provide facility to generate Open API 3.0 Specification commonly used by Swagger UI. The API specification directly generated from controllers metadata.

Enable The Facility#

To enable this facility you need to install the @plumier/swagger and use the SwaggerFacility on existing Plumier application like below:

import { SwaggerFacility } from "@plumier/swagger"
new Plumier()
// ...... other facility
// activate Open Api generation and Swagger UI
.set(new SwaggerFacility())

Above is the minimum configuration required to generate the Open Api 3.0 Specification, some configuration may needed but optional.

Using above code Plumier automatically generate Open API 3.0 Specification using controllers metadata and create two endpoints:

  • /swagger.json The Open API 3.0 Specification
  • /swagger The swagger UI (API explorer)

Swagger Endpoint#

By default the endpoint of the Swagger ui is /swagger this endpoint is customisable by providing endpoint on the SwaggerFacility like below:

import { SwaggerFacility } from "@plumier/swagger"
new Plumier()
// ...... other facility
.set(new SwaggerFacility({ endpoint: "/explorer" }))

Above code will host the Swagger ui in /explorer endpoint.

Project Info#

Swagger facility provide default project info for OpenAPI 3.0 spec, you can override this by providing it in facility constructor

import { SwaggerFacility } from "@plumier/swagger"
new Plumier()
// ...... other facility
.set(new SwaggerFacility({
info: {
title: "Pet Api Explorer",
version: "1.0.0",
description: "Lorem ipsum"
}
}))