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

feat(generate): add option to disable output validation #53

Merged
merged 2 commits into from
Jul 23, 2024
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
2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ env:
mocha: true
extends: 'eslint:recommended'
parserOptions:
ecmaVersion: 8
ecmaVersion: 2020
sourceType: 'script'
rules:
indent:
Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
.then((result) => {
Logger.info('Input is valid');
if (!options.functional) {
console.log(result);

Check warning on line 70 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 70 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 70 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 70 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement

Check warning on line 70 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, windows-latest)

Unexpected console statement

Check warning on line 70 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, windows-latest)

Unexpected console statement
}
})
.catch((err) => {
Expand Down Expand Up @@ -234,7 +234,7 @@
return Commands.parse(argv.model, argv.resolve, argv.all, argv.output, options)
.then((result) => {
if (result) {
console.log(result);

Check warning on line 237 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 237 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 237 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 237 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement

Check warning on line 237 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, windows-latest)

Unexpected console statement

Check warning on line 237 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, windows-latest)

Unexpected console statement
}
})
.catch((err) => {
Expand Down Expand Up @@ -353,7 +353,7 @@
if (argv.output){
fs.writeFileSync(argv.output, cto);
} else {
console.log(cto);

Check warning on line 356 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 356 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 356 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 356 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement

Check warning on line 356 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, windows-latest)

Unexpected console statement

Check warning on line 356 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, windows-latest)

Unexpected console statement
}
} catch (err){
Logger.error(err);
Expand Down Expand Up @@ -395,14 +395,20 @@
type: 'boolean',
default: false,
});
yargs.option('disableValidation', {
describe: 'Do not validate generated output',
type: 'boolean',
default: false
});
}, argv => {
return Commands.generate(argv.model, argv.concept, argv.mode, {
optionalFields: argv.includeOptionalFields,
metamodel: argv.metamodel,
strict: argv.strict,
disableValidation: argv.disableValidation
})
.then(obj => {
console.log(JSON.stringify(obj, null, 2));

Check warning on line 411 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 411 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 411 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 411 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement

Check warning on line 411 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, windows-latest)

Unexpected console statement

Check warning on line 411 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, windows-latest)

Unexpected console statement
})
.catch((err) => {
Logger.error(err.message);
Expand Down Expand Up @@ -450,7 +456,7 @@

return Commands.decorate(argv.models, argv.decorator,argv.vocabulary,options)
.then(obj => {
console.log(obj);

Check warning on line 459 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 459 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 459 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 459 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement

Check warning on line 459 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, windows-latest)

Unexpected console statement

Check warning on line 459 in index.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, windows-latest)

Unexpected console statement
})
.catch((err) => {
Logger.error(err.message);
Expand Down
3 changes: 2 additions & 1 deletion lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@
for (const finding of results.findings) {
const result = compareResultToString(finding.result);
const coloredResult = this.colorCompareResult(result);
console.log(`[${finding.key}]: ${finding.message} (${coloredResult})`);

Check warning on line 286 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 286 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 286 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 286 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement

Check warning on line 286 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, windows-latest)

Unexpected console statement

Check warning on line 286 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, windows-latest)

Unexpected console statement
}
const result = compareResultToString(results.result);
const coloredResult = this.colorCompareResult(result);
console.log('');

Check warning on line 290 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 290 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 290 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 290 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement

Check warning on line 290 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, windows-latest)

Unexpected console statement

Check warning on line 290 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, windows-latest)

Unexpected console statement
console.log(`overall result: ${coloredResult}`);

Check warning on line 291 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 291 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 291 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 291 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement

Check warning on line 291 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, windows-latest)

Unexpected console statement

Check warning on line 291 in lib/commands.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, windows-latest)

Unexpected console statement
if (result === 'error') {
process.exit(1);
}
Expand All @@ -305,6 +305,7 @@
* @param {string} [options.optionalFields] if true, optional fields will be included in the output
* @param {boolean} [options.strict] - require versioned namespaces and imports
* @param {boolean} [options.metamodel] - include the Concerto Metamodel
* @param {boolean} [options.disableValidation] - do not validate the generated output
*/
static async generate(ctoFiles, concept, mode, options) {
const modelManagerOptions = { offline: options && options.offline, strict: options && options.strict };
Expand Down Expand Up @@ -342,7 +343,7 @@
);
const serializer = new Serializer(factory, modelManager);

return Promise.resolve(serializer.toJSON(resource));
return Promise.resolve(serializer.toJSON(resource, {validate: !options?.disableValidation}));
}

/**
Expand Down
Loading