swagger-json
Generate swagger json schema based on Joi schemas.
Installation
npm install swagger-json
Usage
const swaggerDoc = ;const Joi = ; const host = 'localhost:3000';const basePath = '/';const info = "version": "1.0.0" "title": "Title Example" "description": "Description API example" "termsOfService": "http://swagger.io/terms/" "contact": "name": "Example team" "license": "name": "MIT" ; // This will generate initial docswaggerDoc; const joiSchema = body: Joiobject email: Joidescription'Email address for new user' password: Joidescription'Password for new user' salt: Joidescription'Salt for new user' headers: Joiobject authorization: ValidationtokenValidationdescription'Auth token' group: 'Register routes' description: 'Route to register user to the system' // create a new routeswaggerDoc; // your swagger json file will have been written to "swagger.json"
Usage without writing the swagger.json file to the file system
// use swaggerDocJson instead of swaggerDoc from the swagger-json moduleconst swaggerDocJson = ; // using the same joiSchema, info, host, and basePath as the above example.swaggerDocJson; const swaggerSpec = swaggerDocJson;