Skip to content

Commit 309c4d1

Browse files
committed
v1.0.0: update readme
1 parent 518b331 commit 309c4d1

File tree

2 files changed

+34
-33
lines changed

2 files changed

+34
-33
lines changed

README.md

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,28 @@ $ npm install outdoc -D
1717
## Usage
1818

1919
Add the following codes into your main file
20-
```
20+
21+
```js
22+
const { OutDoc } = require('outdoc')
23+
if (process.env.NODE_ENV === "test") {
24+
OutDoc.init()
25+
}
2126
```
2227

28+
Run the command
29+
2330
```bash
2431
$ npx outdoc [test command] [options]
2532
```
2633

27-
Usually it could be:
34+
Usually it could be, for example:
2835

2936
```bash
3037
$ npx outdoc npm test -t project-name
3138
```
3239

33-
Finally it will generate an api.yaml in your root folder by default
40+
Adn it will generate an api.yaml in your root folder by defaults
41+
3442

3543
## Options
3644

@@ -43,49 +51,42 @@ Finally it will generate an api.yaml in your root folder by default
4351
-h, --help display help for command
4452
```
4553

54+
## Not adding extra codes
55+
You might don't wanna add any extra codes in your project only for generating API document, then you can do:
4656

57+
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.
4758

48-
49-
50-
## Configuration
51-
Check if the field `main` in your package.json pointing to the file where the node server exported.
52-
53-
If not, add `output.main` pointing to the file, e.g.:
54-
55-
```
59+
```json
5660
{
57-
...
58-
"outdoc": {
59-
"main": "./server/index.js"
60-
}
61+
"outdoc": {
62+
"main": "./src/app.ts"
63+
}
6164
}
6265
```
6366

67+
Then run the command with the option **-f**
6468

65-
## Typescript projects
66-
Add `output.main` in your package.json pointing to the file where the nodejs server exported, e.g.:
67-
69+
```bash
70+
$ npx outdoc npm test -f
6871
```
69-
{
70-
...
71-
"outdoc": {
72-
"main": "./src/app.ts"
73-
}
74-
}
7572

76-
```
77-
afte that you can run the script as usual
73+
#### What is happending behind `-f`
74+
75+
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.
76+
77+
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:
7878

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

80-
## Behind the screen
8184

82-
Outdoc make use the node module `async_hooks` to understand all the HTTP request to the nodejs server.
85+
## Notes
8386

84-
When you running the e2e testing, you are like telling outdoc "ok, this is a 200 request if you pass in such request body", "and this endpoint can return 403 with a code 100", etc. Outdoc will generate the api doc based on that.
87+
Outdoc can only understand tests who are sending and receiving real HTTP requests, for example using the [supertest](https://github.com/visionmedia/supertest) in your test cases.
8588

86-
So if you wanna have a completed API doc, you need
87-
1. Writing e2e test covering all the cases of your API.
88-
2. Running e2e test with real http request, that means testing tools like supertest is a fit, but fastify.inject won't work.
89+
Mocked HTTP request won't work with Ourdoc, like fastify.inject.
8990

9091
## License
9192

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "outdoc",
3-
"version": "0.2.0",
3+
"version": "1.0.0",
44
"description": "Auto-generate OpenAPI document for Node.js service from the local testing",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

0 commit comments

Comments
 (0)