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:
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.jsonThe Open API 3.0 Specification/swaggerThe swagger UI (API explorer)
note
Swagger UI and swagger.json will be disabled on production. To force enable SwaggerUI on production, use environment variable PLUM_ENABLE_SWAGGER with value ui, json or false.
Swagger Endpoint#
By default the endpoint of the Swagger ui is /swagger this endpoint is customisable by providing endpoint on the SwaggerFacility like below:
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
Decorator Customization (Optional)#
Plumier provided decorators to customize the appearance of the swagger UI
Description#
Description can be applied on the action or parameter like below
Description receive string with markdown syntax
Response#
Open API generator automatically check for action return type to generate the response schema. Keep in mind that when provided Promise you need to specify the return type manually like below.
Custom Authentication#
Plumier provided configuration to add custom authentication schema used to show the Swagger authentication dialog. To do that you can provide a custom facility to setup the configuration like below.
Using above configuration will add another authentication alternative on the Swagger UI.
