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 🙏

© 2026 – Pkg Stats / Ryan Hefner

z-openapi

v1.4.7

Published

Library to help writing swagger file definition

Readme

z-openapi

z-openapi can help you create swagger definition.

From a Zopenapi instance, each component and subcomponent are fluents. You can describe them either with a plain javascript object, either with a factory function who takes and returns a fluent builder instance. Some components have helpers functions to help saving time.

eg: <Schema instance>.string(true) for <Schema instance>.type('string').required(true)

Typescript hint enabled ! Yeay ! Let's dive into it !

In a Node project install z-openapi

$ npm install --save z-openapi

At some point in your code, import Zopenapi class, and export an instance for other modules to enhance it.

import { Zopenapi } from 'z-openapi';
export const zoa = new Zopenapi();

Describe top level informations

zoa
	.info(info => info // this is the builder instance
		.title('Swagger title')
		.version('1.0.0')
		.description('Swagger description')
		
		// Same for each compnt / subcompnt:
		
		// Equivalent
		// .license({ name: 'ISC' }) // plain openapi object
		.license(license => license.name('ISC')) // factory function
		
		.contact(contact => contact
			.name('Swagger contact name')
			.email('Swagger contact email')
			.url('Swagger contact url')
		)
	)
	.servers(
		{ url: 'http://localhost:3000' },
		{ url: 'https://another-hostname.com' },
	)
	.components(components => components
		.schemas({
			BaseError: baseError => baseError.object({
				name: name => name.string(true).description('Swagger schema description'),
				message: message => message.string(true),
			}).description('Swagger schema description'),
		})
		  
		.securitySchemes({
			bearer: bearer => bearer.name('Authorization').in('header'),
			apikey: apikey => apikey.name('api-key').in('query'),
		})
		.
	);
	
/*
.
.
.
*/

Add more schemas in your model's modules

	zoa.componentsSchemas({
		  
		User: user => user.object({
			id: id => id.string(),
			email: email => email.string(true),
			password: password => password.string(),
		}),

		Users: users => users.array(items => items.ref('User')),
			
		CreateUser: user => user.object({
			email: email => email.string(true),
			password: password => password.string(true),
		}),

		UpdateUser: user => user.object({
			email: email => email.string(),
			password: password => password.string(),
		})
	});

Add paths in your router's modules

zoa.paths({

	'/users': path => path
		.get(get => get
			.response200(resp => resp.jsonSchema(json => json.ref('Users')))
			.security({ bearer: [] })
		)
		.post(post => post
			.requestBody(body => body.jsonSchema(json => json.ref('CreateUser')))
			.response200(resp => resp.jsonSchema(json => json.ref('User')))
			.security({ apikey: [] })
		),

	'/users/{id}': path => path
		.get(get => get
			.parameters(param => param.name('id'))
			.response200(resp => resp.jsonSchema(json => json.ref('User')))
			.security({ bearer: [] })
		)
		.put(put => put
			.parameters(param => param.name('id'))
			.requestBody(body => body.jsonSchema(json => json.ref('UpdateUser')))
			.response200(resp => resp.jsonSchema(json => json.ref('User')))
			.security({ bearer: [] })
		)
		.delete(del => del
			.parameters(param => param.name('id'))
			.response200(resp => resp.jsonSchema(json => json.ref('User')))
			.security({ bearer: [] })
		)
});

Finnaly, to get it serve by swagger-ui

import swaggerUi from 'swagger-ui-express';
	
/*
.
.
.
*/

app.use('/docs',  swaggerUi.serve,  swaggerUi.setup(zoa.js()));