Skip to content

Commit 8777b72

Browse files
Merge pull request #3 from ScottLogic/simplify-tests
fix: formatter is now a JS module
2 parents d42f555 + 239ecb8 commit 8777b72

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
## OpenAPI Forge - JavaScript
22

3-
This repository is the JavaScript template for the [OpenAPI Forge](https://github.com/ColinEberhardt/openapi-forge), see that repository for usage instructions:
3+
This repository is the JavaScript generator for the [OpenAPI Forge](https://github.com/ScottLogic/openapi-forge), see that repository for usage instructions:
44

55
https://github.com/ScottLogic/openapi-forge
66

77
## Development
88

9+
### Running
10+
11+
To run this generator, you also need to have [OpenAPI Forge] installed, or the repository checked out. Assuming you have it installed as a global module, you can run this generator as follows:
12+
13+
```
14+
$ openapi-forge forge
15+
\ https://petstore3.swagger.io/api/v3/openapi.json
16+
\ .
17+
\ -o api
18+
```
19+
20+
This generates an API from the Pet Store swagger definition, using the generator within the current folder (`.`), outputting the results to the `api` folder.
21+
922
### Testing
1023

1124
The standard test script is used to execute the BDD-style tests against this generator.

formatter.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// there are issues with running prettier as a CLI command
2+
// see: https://github.com/ScottLogic/openapi-forge/issues/133
3+
// this is a workaround to run the prettier CLI as a node module
4+
const cli = require("prettier/cli.js");
5+
6+
// map forge log levels to prettier log levels
7+
const logLevels = [
8+
/* quiet */
9+
"silent",
10+
/* standard */
11+
"warn",
12+
/* verbose */
13+
"debug",
14+
];
15+
16+
module.exports = (folder, logLevel) => {
17+
cli.run(["--write", folder, "--loglevel", logLevels[logLevel]]);
18+
};

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"test:generators": "\"./node_modules/.bin/cucumber-js\" -p generators",
1212
"format:check:all": "prettier --check .",
1313
"format:write:all": "prettier --write .",
14-
"format:write": "prettier --write",
1514
"lint:check:all": "eslint .",
1615
"lint:write:all": "eslint --fix ."
1716
},

partials/modelIncludes.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{#if models}}
1+
{{#if models }}
22
const {
33
{{#each models}}{{@key}}, {{/each}}
44
} = require("./model");

0 commit comments

Comments
 (0)