Skip to content

Commit 9f4c942

Browse files
author
Alessandro Romanelli
committed
Improved help messages and updated README
1 parent 398924b commit 9f4c942

File tree

7 files changed

+71
-19
lines changed

7 files changed

+71
-19
lines changed

README.md

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,64 @@
11
# ExpressO
2-
An Express.js tool to statically analyze the backend, generating the specification for its routes using the OpenAPI standard.
2+
An Express.js CLI tool to statically analyze the backend, generating the specification for its routes using the OpenAPI standard.
33

44
## Context
55
This software is developed in the context of the 2022 Spring semester for the Master Thesis in Software & Data Engineering.
66

77
## How to install
8-
`npm install expresso`, (optionally -g to install globally);
8+
`npm install -g expresso`
99

10-
## How to use
11-
There are several ways to use the tool:
12-
- `expresso generate`: will statically analyze your project and generate the corresponding `openapi.yaml` OpenAPI 3.0 specification;
13-
- `expresso monitor`: will generate the OpenAPI 3.0 specification and add middleware to your Express.js application to monitor route usage and infer payloads schemas;
14-
- `expresso test <custom_specification>`: will evaluate the generated specification against your provided specification and generate a report of mismatches.
10+
This will allow you to use the `expresso` command from anywhere.
1511

16-
## Acknowledgements
12+
## Requirements
13+
The project for which you wish to generate the OpenAPI specification should:
14+
- be an Express.js project;
15+
- be able to complete the start-up without any errors;
16+
17+
## Commands &mdash; How to use
18+
### Generate
19+
This command is used to generate the OpenAPI3.0 specification relative to an Express.js project by statically analyzing it.
20+
21+
Usage: `expresso generate [--root] [--start] [--output] [--ext]`
22+
23+
Description:
24+
25+
| Command | Alias | Description | Default |
26+
|------------|-------|-------------------------------------------------------------------------------------------------------------------------------|----------------------|
27+
| `--root` | | Specifies the root of the Express.js project to generate an OpenAPI specification for, defaults to current working directory. | `process.cwd()` |
28+
| `--start` | | The command line that will be used to start the project. | `npm start` |
29+
| `--output` | `-O` | Specifies a path of where to output the OpenAPI specification. | `./expresso-openapi` |
30+
| `--ext` | `-E` | Specifies which format to use for the output between `json` and `yaml`. | `json` |
31+
32+
### Monitor
33+
This command is similar to `generate` but will continue monitoring the backend and periodically update the OpenAPI3.0 specification with metrics about the data coming through the routes.
34+
35+
Not implemented yet.
36+
37+
### Test
38+
This command takes as input another specification and compares it to the one that the tool is able to generate.
39+
40+
Not implemented yet.
41+
42+
### Compare
43+
Usage: `expresso compare <fileA> <fileB> [--json]`
44+
45+
Description:
46+
47+
| Command | Alias | Description | Default |
48+
|----------|-------|----------------------------------------------------------------|---------|
49+
| `--json` | `-J` | Specifies to produce a JSON instead of a human readable report | `False` |
50+
51+
## Limitations
52+
Currently, the tool only allows users to extract all the endpoints registered in the application and the corresponding response codes.
53+
This should suffice to generate the skeleton of a valid OpenAPI documentation.
54+
55+
## Known Issues
56+
- The response mining has issues with local identifiers. Global constants are self explanatory but local variables (e.g: `status`) does not say anything about the type of response.
57+
58+
## Contributors
59+
60+
| Title | Full Name | Association | Role |
61+
|-------|----------------------|-----------------------------------|------------|
62+
| | Alessandro Romanelli | | Developer |
63+
| Prof. | Cesare Pautasso | Software Institute (Design Gorup) | Advisor |
64+
| | Souhaila Serbout | Software Institute (Design Group) | Co-advisor |

src/cli/commands/compare.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export const parseCompareCommandLineArgs = (argv: string[]): CLIOptionsCompare =
99
];
1010

1111
const parseOptions = commandLineArgs(parseCommandDefinitions, { stopAtFirstUnknown: true, argv });
12+
if (parseOptions.help) return {
13+
fileA: "", fileB: "", json: false, help: true
14+
}
15+
1216
if (!parseOptions.files || parseOptions.files.length < 2) {
1317
throw new Error('Must provide at least two file paths as arguments');
1418
}

src/lib/expresso/compare.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ export const expressoCompare = async (options: CLIOptionsCompare): Promise<void>
1212

1313
if (options.help)
1414
return console.log(
15-
`Usage: expresso compare <fileA> <fileB> [options]
15+
`Usage: expresso compare <fileA> <fileB> [--json]
1616
1717
This command compare two user-provided specifications and generates a report of how much the OAPI specification of fileB covers what is specified in fileA.
1818
1919
Available options:
2020
${table(
2121
[
22-
['-H', '--help', 'Prints to console description and options for this command'],
2322
['-J', '--json', 'Switches output from human-readable to JSON format'],
2423
],
2524
tableOptions,

src/lib/expresso/generate.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ const tableOptions = {
1212
export const expressoGenerate = async (options: CLIOptionsGenerate): Promise<void> => {
1313
if (options.help) {
1414
return console.log(
15-
`Usage: expresso generate [root, start, output, ext]
15+
`Usage: expresso generate [--root] [--start] [--output] [--ext]
1616
1717
Options descriptions:
1818
${table(
1919
[
2020
[
21-
'root',
21+
'--root',
2222
'the root of the Express.js project to generate an OpenAPI specification for, defaults to current working directory',
2323
],
24-
['start', "command line that will be used to start the project, defaults to 'npm start'"],
25-
['output', "specify a path of where to output the OpenAPI specification, defaults to './expresso-openapi'"],
26-
['ext', "specify which format to use for the output, defaults to 'json'"],
24+
['--start', "command line that will be used to start the project, defaults to 'npm start'"],
25+
['--output', "specify a path of where to output the OpenAPI specification, defaults to './expresso-openapi'"],
26+
['--ext', "specify which format to use for the output, defaults to 'json'"],
2727
],
2828
tableOptions,
2929
)}

src/lib/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { expresso } from './expresso';
33
import { ExpressProxy as Express, RouterProxy as Router } from './proxy';
44
import * as real_express from 'express-original';
55

6-
// TODO: Different versions of express?
76
module.exports = Express;
87

98
for (const k of Object.keys(real_express)) {
10-
Reflect.set(module.exports, k, Reflect.get(real_express, k));
9+
module.exports[k] = Reflect.get(real_express, k);
1110
}
1211

1312
module.exports.Router = Router;
1413
module.exports.expresso = expresso;
14+

src/lib/proxy/model/Handler.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export class Handler {
5050
const fullPath = path.normalize(`${basePath}${p}`);
5151
Object.assign(endpoints, this._routers[p].getEndpoints(fullPath));
5252
}
53-
5453
return endpoints;
5554
}
5655

src/lib/replacer/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export const replaceExpress = async (basePath: string): Promise<boolean> => {
5959
path.resolve(npmLibFolder, 'node_modules/expresso-api'),
6060
path.resolve(basePath, '.expresso-runtime/node_modules/express'),
6161
{
62-
recursive: true
62+
recursive: true,
63+
overwrite: true
6364
}
6465
)
6566

@@ -82,6 +83,7 @@ export const replaceExpress = async (basePath: string): Promise<boolean> => {
8283
path.resolve(basePath, '.expresso-runtime/node_modules/express-original'),
8384
{
8485
recursive: true,
86+
overwrite: true
8587
},
8688
);
8789
logger.info(`Created 'express' proxy within work copy`);

0 commit comments

Comments
 (0)