Skip to content

Commit

Permalink
fix: test-generator command
Browse files Browse the repository at this point in the history
  • Loading branch information
ms14981 authored and ColinEberhardt committed Feb 2, 2023
1 parent b82121a commit bfa18e3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CICD/compareTestResults.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs");

const log = require("../src//common/log");
const log = require("../src/common/log");

log.setLogLevel(log.logLevels.verbose);

Expand Down
2 changes: 1 addition & 1 deletion src/forge/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require("path");
const fs = require("fs");

const generate = require("./generate");
const generate = require("../generate");
const generatorResolver = require("../common/generatorResolver");
const {
configToCommanderOptions,
Expand Down
13 changes: 9 additions & 4 deletions src/forge/generate.js → src/generate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// IMPORTANT: This file is used in the generators, so you will need to change them if this file is moved.
// See issue https://github.com/ScottLogic/openapi-forge/issues/158

const fs = require("fs");

const path = require("path");
Expand All @@ -7,10 +10,10 @@ const minimatch = require("minimatch");
const fetch = require("node-fetch");
const { parse } = require("yaml");

const generatorResolver = require("../common/generatorResolver");
const helpers = require("../helpers");
const log = require("../common/log");
const transformers = require("../transformers");
const generatorResolver = require("./common/generatorResolver");
const helpers = require("./helpers");
const log = require("./common/log");
const transformers = require("./transformers");
const SwaggerParser = require("@apidevtools/swagger-parser");
const converter = require("swagger2openapi");

Expand Down Expand Up @@ -157,6 +160,8 @@ 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) {
log.setLogLevel(options.logLevel);
log.logTitle();
Expand Down
13 changes: 12 additions & 1 deletion src/testGenerators/testGenerators.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,18 @@ function testGenerators(options) {
options.generators.forEach((generator) => {
try {
const generatorPath = path.resolve(
path.join(__dirname, "..", "..", generator)
// Assuming the file structure:
// - openapi-forge
// |- src
// |- testGenerators
// |- testGenerators.js
// - openapi-forge-javascript
// - openapi-forge-...
//
// The generators must be in the above location, otherwise this test-generators command will not work.
// If you move this file, the test-generators command will not work unless you fix the line below.
// We need to go up three directories to get to the root of openapi-forge:
path.join(__dirname, "..", "..", "..", generator)
);

log.standard(`Starting tests for generator ${generator}`);
Expand Down
2 changes: 1 addition & 1 deletion test/generate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const fs = require("fs");
const path = require("path");
const Handlebars = require("handlebars");

const generate = require("../src/forge/generate");
const generate = require("../src/generate");
const generatorResolver = require("../src/common/generatorResolver");

jest.mock("fs");
Expand Down

0 comments on commit bfa18e3

Please sign in to comment.