Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swagb

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagb

Simple swagger schema builder

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
0
Weekly downloads
 
Created
Source

Simple Swagger Builder

Get started

npm install swagb

Example

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

// Joi for schema generation, can be replaced with any other schema generator
const Joi = require("joi");
const jts = require("joi-to-swagger");

const swagb = require("swagb");

const swaggerDocument = swagb
  .api("3.0.0")
  .info({
    title: "API Documentation",
    version: "1.0.0",
    description: "Documentation for your API",
  })
  .paths({
    "/entity/{uuid}": swagb
      .put()
      .summary("Update entity")
      .description("Endpoint to update entity")
      .tags(["Location"])
      .security([{ bearerAuth: [] }])
      .request(
        swagb
          .request()
          .required()
          .json(
            jts(
              Joi.object().keys({
                name: Joi.string().required(),
                address: Joi.string().required(),
                city: Joi.string().required(),
                state: Joi.string().required(),
                zip: Joi.string().required(),
                country: Joi.string().required(),
              })
            ).swagger
          )
      )
      .responses({
        200: swagb
          .response()
          .description("Entity updated successfully")
          .json(
            jts(
              Joi.object().keys({
                message: Joi.string().required(),
              })
            ).swagger
          ),
      }),
  })
  .components({
    securitySchemes: {
      bearerAuth: {
        type: "http",
        scheme: "bearer",
      },
    },
  })
  .compile();

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));

app.listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

Keywords

FAQs

Package last updated on 22 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc