Skip to content

Commit

Permalink
fix: test-generators command by reverting generate
Browse files Browse the repository at this point in the history
  • Loading branch information
ms14981 authored and ColinEberhardt committed Feb 3, 2023
1 parent 2a8a4e6 commit 2d63fdb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/forge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ const forgeCommand = function (program) {
process.env[optionName] = options[option];
});

await generate(schema, generatorPath, options);
generatorResolver.cleanup();
await generate(schema, generatorPathOrUrl, options);
});

// add the additional options from the generator's config.json file
Expand Down
8 changes: 7 additions & 1 deletion src/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,17 @@ function getFilesInFolders(basePath, partialPath = "") {

// IMPORTANT: This function is used in the generators, so be careful when modifying!
// See issue https://github.com/ScottLogic/openapi-forge/issues/158
async function generate(schemaPathOrUrl, generatorPath, options) {
async function generate(schemaPathOrUrl, generatorPathOrUrl, options) {
log.setLogLevel(options.logLevel);
log.logTitle();
let exception = null;
let numberOfDiscoveredModels = 0;
let numberOfDiscoveredEndpoints = 0;
try {
log.standard(`Loading generator from '${generatorPathOrUrl}'`);

let generatorPath = generatorResolver.getGenerator(generatorPathOrUrl);

log.standard("Validating generator");
validateGenerator(generatorPath);

Expand Down Expand Up @@ -270,6 +274,8 @@ async function generate(schemaPathOrUrl, generatorPath, options) {
}
} catch (e) {
exception = e;
} finally {
generatorResolver.cleanup();
}

if (exception === null) {
Expand Down
1 change: 1 addition & 0 deletions test/generate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("generate", () => {
fs.existsSync.mockReturnValue(true);
fs.readFileSync.mockReturnValue(fakeSchema);
generatorResolver.isUrl.mockReturnValue(false);
generatorResolver.getGenerator.mockImplementation((path) => path);
Handlebars.compile.mockReturnValue(() => outCode);

const generatorPackage = {
Expand Down

0 comments on commit 2d63fdb

Please sign in to comment.