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

outdoc

v1.0.1

Published

Auto-generate OpenAPI document for Node.js service from the local testing

Downloads

9

Readme

Outdoc

Auto generate OpenAPI document from local HTTP testing

Version npm download

colorful robot writing document by Stable Diffusion

Installation

$ npm install outdoc -D

Usage

Add the following codes into your main file

const { OutDoc } = require('outdoc')
if (process.env.NODE_ENV === "test") {
  OutDoc.init()
}

Run the command

$ npx outdoc [test command] [options]

Usually it could be, for example:

$ npx outdoc npm test -t project-name

Adn it will generate an api.yaml in your root folder by defaults

Options

  -o, --output            file path of the generated doc, format supports json and yaml, default: api.yaml
  -t, --title <string>    title of the api document, default: API Document
  -v, --version <string>  version of the api document, default: 1.0.0
  -e, --email <string>    contact information
  -f, --force             run the script without adding OutDoc.init in the code 
  -h, --help              display help for command

Not adding extra codes

You might don't wanna add any extra codes in your project only for generating API document, then you can do:

First, Check if the main in your package.json pointing to your app entry file which export your nodejs server. If not, please add the attribute outdoc pointing to it. If you are writting a Typescript project, you need to add the following configuration.

{
	"outdoc": {
		"main": "./src/app.ts"
	}
}

Then run the command with the option -f

$ npx outdoc npm test -f

What is happending behind -f

By using the option -f, Outdoc will first check the outdoc.main in your package.json, if it not exist, Outdoc will use main in the package.json to find the app entry file.

Then Outdoc will copy the entry app file and insert codes into it, and use the new copied file as the entry app file, the concrete steps are:

  1. Find your app entry file from package.json, for example the file is named as app.js
  2. Copy app.js to a new temporary file named tmp_outdoc_file
  3. Insert Outdoc.init into app.js and start running the program to generate the API doc
  4. After the generation finished, copy back the content of tmp_outdoc_file to app.js and remove tmp_outdoc_file

Notes

Outdoc can only understand tests who are sending and receiving real HTTP requests, for example using the supertest in your test cases.

Mocked HTTP request won't work with Ourdoc, like fastify.inject.

License

MIT