Skip to content

ShopBonsai/no-hassle

Repository files navigation

No Hassle

Makes Node.js route handling easy with support for Joi schema validation and automatic Swagger generation based on these schema definitions. Uses Expressjs routing mechanism.

  • ✅ Easy to maintain Joi schemas

  • ✅ Input validation

  • ✅ Easy integration tests data output validation

  • ✅ No more manual Swagger files, ever!

  • ✅ No extra comments above every function to expose

  • 🛠 Automatic mocked routes with the switch of a boolean (in progress)

  • 🛠 Automatic fully generated SDK file based on your routes (in progress)

Installation

Install via npm

npm install no-hassle

or via yarn

yarn add no-hassle

Usage

const express = require('express');
const swaggerUi = require("swagger-ui-express");

const { router, getSwagger } = require('no-hassle');

// Create Express app instance
const app = express();

// Declare route(s)
router.use(app, '/users')
  .get('/', {
    description: 'Get all users',
    tags: ['Users'],
    output: {
      [httpStatus.OK]: userOutputSchema, // Joi schema
    },
  },
    (req, res) => { ... }

// Get autogenerated Swagger
const swagger = getSwagger({
  version: '1.0.0',
  title: 'My super cool API',
  description: 'This describes all exposed api endpoints',
});

// Serve swagger-ui
app.use("/docs", swaggerUi.serve, swaggerUi.setup(swagger))

// Start server
app.listen(4000)

This will start an Express server with one route and autogenerated Swagger documentation based on the description, tags and output schema.

Remarks

Current support

Authors

See the list of contributors who participated in this project.

License

This project is licensed under the ISC License - see the LICENSE.md file for details

About

Save yourself some hassle keeping Swagger up-to-date, maintaining input validation and Typescript interfaces

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published