Skip to content

Commit

Permalink
fix: formatter is now a JS module
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinEberhardt committed Dec 19, 2022
1 parent 31a4dee commit 239ecb8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ https://github.com/ScottLogic/openapi-forge

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:

~~~
```
$ openapi-forge forge
\ https://petstore3.swagger.io/api/v3/openapi.json
\ .
\ -o api
~~~
```

This generates an API from the Pet Store swagger definition, using the generator within the current folder (`.`), outputting the results to the `api` folder.

Expand Down
18 changes: 18 additions & 0 deletions formatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// there are issues with running prettier as a CLI command
// see: https://github.com/ScottLogic/openapi-forge/issues/133
// this is a workaround to run the prettier CLI as a node module
const cli = require("prettier/cli.js");

// map forge log levels to prettier log levels
const logLevels = [
/* quiet */
"silent",
/* standard */
"warn",
/* verbose */
"debug",
];

module.exports = (folder, logLevel) => {
cli.run(["--write", folder, "--loglevel", logLevels[logLevel]]);
};
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"test:generators": "\"./node_modules/.bin/cucumber-js\" -p generators",
"format:check:all": "prettier --check .",
"format:write:all": "prettier --write .",
"format:write": "prettier --write",
"lint:check:all": "eslint .",
"lint:write:all": "eslint --fix ."
},
Expand Down
2 changes: 1 addition & 1 deletion partials/modelIncludes.handlebars
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#if models}}
{{#if models }}
const {
{{#each models}}{{@key}}, {{/each}}
} = require("./model");
Expand Down

0 comments on commit 239ecb8

Please sign in to comment.