1.0.1 • Published 2 years ago

outdoc v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

1.0.1

2 years ago

1.0.0

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.1-init.2

2 years ago

0.0.1-init.1

2 years ago