From 31a4deee52ef8ff1435212cfd1ac51eb30b0bbe9 Mon Sep 17 00:00:00 2001 From: Colin Eberhardt Date: Mon, 19 Dec 2022 14:15:25 +0000 Subject: [PATCH 1/2] docs: minor README changes --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f13db7..ad1c374 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,24 @@ ## OpenAPI Forge - JavaScript -This repository is the JavaScript template for the [OpenAPI Forge](https://github.com/ColinEberhardt/openapi-forge), see that repository for usage instructions: +This repository is the JavaScript generator for the [OpenAPI Forge](https://github.com/ScottLogic/openapi-forge), see that repository for usage instructions: https://github.com/ScottLogic/openapi-forge ## Development +### Running + +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. + ### Testing The standard test script is used to execute the BDD-style tests against this generator. From 239ecb883a25f2d52374627753d0bb3763eb1de5 Mon Sep 17 00:00:00 2001 From: Colin Eberhardt Date: Mon, 19 Dec 2022 14:15:48 +0000 Subject: [PATCH 2/2] fix: formatter is now a JS module --- README.md | 4 ++-- formatter.js | 18 ++++++++++++++++++ package.json | 1 - partials/modelIncludes.handlebars | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 formatter.js diff --git a/README.md b/README.md index ad1c374..f5797b9 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/formatter.js b/formatter.js new file mode 100644 index 0000000..432feae --- /dev/null +++ b/formatter.js @@ -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]]); +}; diff --git a/package.json b/package.json index b8a6878..72ede02 100644 --- a/package.json +++ b/package.json @@ -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 ." }, diff --git a/partials/modelIncludes.handlebars b/partials/modelIncludes.handlebars index 531a268..eab439f 100644 --- a/partials/modelIncludes.handlebars +++ b/partials/modelIncludes.handlebars @@ -1,4 +1,4 @@ -{{#if models}} +{{#if models }} const { {{#each models}}{{@key}}, {{/each}} } = require("./model");