npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

swaggiffy

v1.0.5

Published

A zero-config Node.js Swagger Documentation Generator.

Downloads

34

Readme

SWAGGIFY

Swaggiffy is a zero config opensource tool for documenting your Node.js Express APIs and is built on top of Swagger. It is designed to be easy to use and simple, with the goal that anyone can read it.

Features

  • Automated Swagger Schema Registry.
  • Automated Swagger API Definition Registry.
  • Automatic Swagger file rendering.
  • Clean and Simple Config file.
  • Supports both OpenAPI 2 and OpenAPI 3.
  • Supports for Typescript Classes.
  • Support for Mongoose ORM Schema Objects.
  • Support for Swagger YAML and JSON.
  • Rich CLI.
  • Built on top on Express and Swagger.

And more ...

Get started

Install

npm i swaggiffy #npm
yarn add swaggiffy #yarn
pnpm add swaggiffy #pnpm

Swaggify Configuration

Swaggify creates a clean and simple configuration file. In addition, it create a swagger definition file, to your preffered path specified in the configuration file.

This is will generate both swaggiffy.config.json and swagger/swagger.json files.

npx swaggiffy init -p PORT

Generate the config file only.

npx swaggify generate:config

Generate the spec file only.

npx swaggify generate:spec

Instantiate Swaggify

In your main .js or .ts file.

const { Swaggiffy } = require('swaggiffy'); // Using require
import { Swaggiffy } from 'swaggiffy'; // Using import

Build Swaggiffy with your express app.

new Swaggiffy().setupExpress(app).swaggiffy();

Using Swaggiffy

Schema Registry

To register a schema

import { registerSchema, registerSchemas } from 'swaggiffy';


registerSchema('Model Name 1', modelObj1); // for plain Js objects
registerSchema('Model Name 2', modelObj2, { orm: 'mongoose' }); // for mongoose model
registerSchema('Model Name 2', modelObj3, { orm: 'sequelize' }); // for sequelize model

registerSchemas([  {'Model Name 1', modelObj1 }, {'Model Name 2', modelObj2, { orm: 'mongoose' }} ]); // for multiple schemas

For classes use

import { Schema } from 'swaggiffy';

@Schema('Model')
class Model {
    property1 = '';
    property2 = '';
    property3 = '';
}

API Definition Registry

We generate API Definition from Express Routers.

tags: Tags are swagger groupings mappedSchema: Maps the desired schema registered in swagger to your API Definition. basePath: Base Paths specifies the route for your router.

import { registerDefinition, registerDefinitions } from 'swaggiffy';

registerDefinition(router, { tags: 'Products', mappedSchema: 'Product', basePath: '/products' });

registerDefinitions([
    router1,
    { tags: 'Products', mappedSchema: 'Product', basePath: '/products' },
    router2,
    { tags: 'Users', mappedSchema: 'User', basePath: '/user' },
]);

Run the App

node app.js

With nodemon we need to exclude files

nodemon --ignore '*swagger.json' app.js

or create a nodemon.json file with

{
    "ignore": ["*swagger.json"]
}

Tada!, Now access localhost:PORT/api-docs to see swagger 😁.

DEMO

Checkout this repository for demo and additional examples. Swaggiffy Samples

CONTRIBUTIONS

You are welcome for contributions. Please read our CONTRIBUTING.md file.

MAINTAINERS