From 6d771da9a9415ae87017600a8cd56dfe1ada087c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathana=C3=ABl=20L=C3=A9caud=C3=A9?= Date: Mon, 10 Dec 2018 13:47:55 -0500 Subject: [PATCH 1/3] JSON node: delete msg.schema before sending msg to avoid conflicts --- .../@node-red/nodes/core/parsers/70-JSON.js | 4 +++ test/nodes/core/parsers/70-JSON_spec.js | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/packages/node_modules/@node-red/nodes/core/parsers/70-JSON.js b/packages/node_modules/@node-red/nodes/core/parsers/70-JSON.js index 4e1e51e47..f696e1f21 100644 --- a/packages/node_modules/@node-red/nodes/core/parsers/70-JSON.js +++ b/packages/node_modules/@node-red/nodes/core/parsers/70-JSON.js @@ -56,6 +56,7 @@ module.exports = function(RED) { RED.util.setMessageProperty(msg,node.property,JSON.parse(value)); if (validate) { if (this.compiledSchema(msg[node.property])) { + delete msg.schema; node.send(msg); } else { msg.schemaError = this.compiledSchema.errors; @@ -70,6 +71,7 @@ module.exports = function(RED) { // If node.action is str and value is str if (validate) { if (this.compiledSchema(JSON.parse(msg[node.property]))) { + delete msg.schema; node.send(msg); } else { msg.schemaError = this.compiledSchema.errors; @@ -87,6 +89,7 @@ module.exports = function(RED) { if (validate) { if (this.compiledSchema(value)) { RED.util.setMessageProperty(msg,node.property,JSON.stringify(value,null,node.indent)); + delete msg.schema; node.send(msg); } else { msg.schemaError = this.compiledSchema.errors; @@ -104,6 +107,7 @@ module.exports = function(RED) { // If node.action is obj and value is object if (validate) { if (this.compiledSchema(value)) { + delete msg.schema; node.send(msg); } else { msg.schemaError = this.compiledSchema.errors; diff --git a/test/nodes/core/parsers/70-JSON_spec.js b/test/nodes/core/parsers/70-JSON_spec.js index 2ff98850f..767d09ecf 100644 --- a/test/nodes/core/parsers/70-JSON_spec.js +++ b/test/nodes/core/parsers/70-JSON_spec.js @@ -433,4 +433,36 @@ describe('JSON node', function() { } }); }); + + it('msg.schema property should be deleted before sending to next node (string input)', function(done) { + var flow = [{id:"jn1",type:"json",action:"str",wires:[["jn2"]]}, + {id:"jn2", type:"helper"}]; + helper.load(jsonNode, flow, function() { + var jn1 = helper.getNode("jn1"); + var jn2 = helper.getNode("jn2"); + jn2.on("input", function(msg) { + should.equal(msg.schema, undefined); + done(); + }); + var jsonString = '{"number":3,"string":"allo"}'; + var schema = {title: "testSchema", type: "object", properties: {number: {type: "number"}, string: {type: "string" }}}; + jn1.receive({payload:jsonString, schema:schema}); + }); + }); + + it('msg.schema property should be deleted before sending to next node (object input)', function(done) { + var flow = [{id:"jn1",type:"json",action:"str",wires:[["jn2"]]}, + {id:"jn2", type:"helper"}]; + helper.load(jsonNode, flow, function() { + var jn1 = helper.getNode("jn1"); + var jn2 = helper.getNode("jn2"); + jn2.on("input", function(msg) { + should.equal(msg.schema, undefined); + done(); + }); + var jsonObject = {"number":3,"string":"allo"}; + var schema = {title: "testSchema", type: "object", properties: {number: {type: "number"}, string: {type: "string" }}}; + jn1.receive({payload:jsonObject, schema:schema}); + }); + }); }); From 3fcfd4abddb36f46dd438ef024a421485ab8385a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathana=C3=ABl=20L=C3=A9caud=C3=A9?= Date: Mon, 10 Dec 2018 14:46:21 -0500 Subject: [PATCH 2/3] JSON node: add help about schema deletion --- .../@node-red/nodes/locales/en-US/parsers/70-JSON.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/nodes/locales/en-US/parsers/70-JSON.html b/packages/node_modules/@node-red/nodes/locales/en-US/parsers/70-JSON.html index 3ec830c33..5783906a3 100644 --- a/packages/node_modules/@node-red/nodes/locales/en-US/parsers/70-JSON.html +++ b/packages/node_modules/@node-red/nodes/locales/en-US/parsers/70-JSON.html @@ -21,7 +21,8 @@
payloadobject | string
A JavaScript object or JSON string.
schemaobject
-
An optional JSON Schema object to validate the payload against.
+
An optional JSON Schema object to validate the payload against. + The property will be deleted before the msg is sent to the next flow.

Outputs

From a97759aa35fbab8645452043fbeee4e853e6c2d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathana=C3=ABl=20L=C3=A9caud=C3=A9?= Date: Mon, 10 Dec 2018 14:47:52 -0500 Subject: [PATCH 3/3] JSON node: add help about schema deletion --- .../@node-red/nodes/locales/en-US/parsers/70-JSON.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/nodes/locales/en-US/parsers/70-JSON.html b/packages/node_modules/@node-red/nodes/locales/en-US/parsers/70-JSON.html index 5783906a3..972b4be33 100644 --- a/packages/node_modules/@node-red/nodes/locales/en-US/parsers/70-JSON.html +++ b/packages/node_modules/@node-red/nodes/locales/en-US/parsers/70-JSON.html @@ -22,7 +22,7 @@
A JavaScript object or JSON string.
schemaobject
An optional JSON Schema object to validate the payload against. - The property will be deleted before the msg is sent to the next flow.
+ The property will be deleted before the msg is sent to the next node.

Outputs