From 1b7553deec1839d05efc26bd5fdefe667cfac76c Mon Sep 17 00:00:00 2001 From: Jerome Simeon Date: Tue, 13 Apr 2021 00:17:41 -0400 Subject: [PATCH] feature(cli) Add --ergo option to CLI validing data for Ergo Signed-off-by: Jerome Simeon --- packages/concerto-cli/index.js | 8 +++++++- packages/concerto-cli/lib/commands.js | 2 +- packages/concerto-core/lib/serializer/jsongenerator.js | 2 ++ packages/concerto-core/test/1.0.0/data/optional1.json | 4 ++++ packages/concerto-core/test/1.0.0/data/optional1b.json | 4 ++++ packages/concerto-core/test/1.0.0/models/optional1.cto | 5 +++++ 6 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 packages/concerto-core/test/1.0.0/data/optional1.json create mode 100644 packages/concerto-core/test/1.0.0/data/optional1b.json create mode 100644 packages/concerto-core/test/1.0.0/models/optional1.cto diff --git a/packages/concerto-cli/index.js b/packages/concerto-cli/index.js index 48ec3414d8..8217219641 100755 --- a/packages/concerto-cli/index.js +++ b/packages/concerto-cli/index.js @@ -44,6 +44,11 @@ require('yargs') type: 'boolean', default: false }); + yargs.option('ergo', { + describe: 'validation and emit for Ergo', + type: 'boolean', + default: false + }); }, (argv) => { if (argv.verbose) { Logger.info(`validate ${argv.input} against the models ${argv.model}`); @@ -53,7 +58,8 @@ require('yargs') argv = Commands.validateValidateArgs(argv); const options = {}; options.offline = argv.offline; - options.functional = argv.functional; + options.functional = !argv.ergo && argv.functional; // XXX Ergo option takes priority + options.ergo = argv.ergo; return Commands.validate(argv.input, argv.model, options) .then((result) => { Logger.info('Input is valid'); diff --git a/packages/concerto-cli/lib/commands.js b/packages/concerto-cli/lib/commands.js index 08b6d5c8f1..a15e8d35fe 100644 --- a/packages/concerto-cli/lib/commands.js +++ b/packages/concerto-cli/lib/commands.js @@ -117,7 +117,7 @@ class Commands { const serializer = new Serializer(factory, modelManager); const object = serializer.fromJSON(json); - return JSON.stringify(serializer.toJSON(object)); + return JSON.stringify(serializer.toJSON(object, {ergo: options.ergo})); } } diff --git a/packages/concerto-core/lib/serializer/jsongenerator.js b/packages/concerto-core/lib/serializer/jsongenerator.js index 0e315e6290..b465497915 100644 --- a/packages/concerto-core/lib/serializer/jsongenerator.js +++ b/packages/concerto-core/lib/serializer/jsongenerator.js @@ -116,6 +116,8 @@ class JSONGenerator { if (!Util.isNull(value)) { parameters.stack.push(value); result[property.getName()] = property.accept(this, parameters); + } else if (this.ergo) { + result[property.getName()] = { '$right' : null }; } } diff --git a/packages/concerto-core/test/1.0.0/data/optional1.json b/packages/concerto-core/test/1.0.0/data/optional1.json new file mode 100644 index 0000000000..09964f19b8 --- /dev/null +++ b/packages/concerto-core/test/1.0.0/data/optional1.json @@ -0,0 +1,4 @@ +{ + "$class": "org.test.C", + "i": 42 +} \ No newline at end of file diff --git a/packages/concerto-core/test/1.0.0/data/optional1b.json b/packages/concerto-core/test/1.0.0/data/optional1b.json new file mode 100644 index 0000000000..8fab2b39e0 --- /dev/null +++ b/packages/concerto-core/test/1.0.0/data/optional1b.json @@ -0,0 +1,4 @@ +{ + "$class": "org.test.C", + "i": null +} \ No newline at end of file diff --git a/packages/concerto-core/test/1.0.0/models/optional1.cto b/packages/concerto-core/test/1.0.0/models/optional1.cto new file mode 100644 index 0000000000..4b6befda80 --- /dev/null +++ b/packages/concerto-core/test/1.0.0/models/optional1.cto @@ -0,0 +1,5 @@ +namespace org.test + +concept C { + o Integer i optional +}