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

@nanoexpress/middleware-schemator

v3.0.11

Published

Schemator middleware for nanoexpress

Downloads

19

Readme

schemator

schemator middleware for nanoexpress

You can think this middleware combine of Swagger documentation and Ajv validation like original nanoexpress built-in feature + swagger-ui middleware

Installation

npm i @nanoexpress/middleware-schemator
# or
yarn add @nanoexpress/middleware-schemator

Schema type

  • YML (preferred)
  • JSON
  • RAW JS Object

YML

const schematorInstance = schemator({ swaggerPath: './swagger.yml' });

app.define(schematorInstance.define);

/// auth/index.js
app.get(
  '/auth',
  // Here any body-parser, form-data logic (all preprocess middlewares)
  schematorInstance.load({
    attach: '/auth',
    method: 'get',
    path: './auth/docs.yml'
  }),
  async (req) => {
    // your logic here
  }
);

JSON

const schematorInstance = schemator({ swaggerPath: './swagger.json' });

app.define(schematorInstance.define);

/// auth/index.js
app.get(
  '/auth',
  // Here any body-parser, form-data logic (all preprocess middlewares)
  schematorInstance.load({
    attach: '/auth',
    method: 'get',
    path: './auth/docs.json'
  }),
  async (req) => {
    // your logic here
  }
);

RAW JS Object

const schematorInstance = schemator({ swaggerRAW: {} });

app.define(schematorInstance.define);

/// auth/index.js
app.get(
  '/auth',
  // Here any body-parser, form-data logic (all preprocess middlewares)
  schematorInstance.load({
    attach: '/auth',
    method: 'get',
    raw: {
      path: {
        '/': {
          /* infos here */
        }
      }
    }
  }),
  async (req) => {
    // your logic here
  }
);

Example

See the examples directory

Usage

ESM Module

import schemator from '@nanoexpress/middleware-schemator';

const schematorInstance = schemator({ swaggerPath: './swagger.yml' });

app.define(schematorInstance.define);

app.get(
  '/auth',
  // Here any body-parser, form-data logic (all preprocess middlewares)
  schematorInstance.load({
    attach: '/auth',
    method: 'get',
    path: './auth/docs.yml'
  }),
  async (req) => {
    // your logic here
  }
);

CJS Module

const bodyParser = require('@nanoexpress/middleware-schemator/cjs');

const schematorInstance = schemator({ swaggerPath: './swagger.yml' });

app.define(schematorInstance.define);

app.get(
  '/auth',
  // Here any body-parser, form-data logic (all preprocess middlewares)
  schematorInstance.load({
    attach: '/auth',
    method: 'get',
    path: './auth/docs.yml'
  }),
  async (req) => {
    // your logic here
  }
);

Options

Initialize options

| Options name | Default | Required | Description | | --------------------- | ------- | ---------------------------- | ------------------------- | | options.swaggerPath | - | Yes or options.swaggerRAW | Swagger schema file path | | options.swaggerRAW | - | Yes or options.swaggerPath | Swagger schema RAW Object |

schematorInstance.load(options, AjvConfig) options

| Options name | Default | Required | Description | | ---------------- | ------- | --------------------- | ------------------------------------------- | | options.method | - | Yes | Your router method (lowercase) | | options.attach | - | Yes | Your router path (with Swagger path format) | | options.path | - | Yes or options.raw | Route Swagger schema file path | | options.raw | - | Yes or options.path | Route Swagger schema RAW Object |

See Ajv configurations for more customization

schematorInstance.render(options) options

| Options name | Default | Required | Description | | -------------------- | --------- | -------- | --------------------------------- | | options.title | Schemator | Yes | Swagger UI Title | | options.exposePath | - | Yes | schematorInstance.expose() path |

License

MIT