Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test-generators command by reverting generate #164

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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