mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
JSON node: delete msg.schema before sending msg to avoid conflicts
This commit is contained in:
parent
6201247875
commit
6d771da9a9
@ -56,6 +56,7 @@ module.exports = function(RED) {
|
|||||||
RED.util.setMessageProperty(msg,node.property,JSON.parse(value));
|
RED.util.setMessageProperty(msg,node.property,JSON.parse(value));
|
||||||
if (validate) {
|
if (validate) {
|
||||||
if (this.compiledSchema(msg[node.property])) {
|
if (this.compiledSchema(msg[node.property])) {
|
||||||
|
delete msg.schema;
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
} else {
|
} else {
|
||||||
msg.schemaError = this.compiledSchema.errors;
|
msg.schemaError = this.compiledSchema.errors;
|
||||||
@ -70,6 +71,7 @@ module.exports = function(RED) {
|
|||||||
// If node.action is str and value is str
|
// If node.action is str and value is str
|
||||||
if (validate) {
|
if (validate) {
|
||||||
if (this.compiledSchema(JSON.parse(msg[node.property]))) {
|
if (this.compiledSchema(JSON.parse(msg[node.property]))) {
|
||||||
|
delete msg.schema;
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
} else {
|
} else {
|
||||||
msg.schemaError = this.compiledSchema.errors;
|
msg.schemaError = this.compiledSchema.errors;
|
||||||
@ -87,6 +89,7 @@ module.exports = function(RED) {
|
|||||||
if (validate) {
|
if (validate) {
|
||||||
if (this.compiledSchema(value)) {
|
if (this.compiledSchema(value)) {
|
||||||
RED.util.setMessageProperty(msg,node.property,JSON.stringify(value,null,node.indent));
|
RED.util.setMessageProperty(msg,node.property,JSON.stringify(value,null,node.indent));
|
||||||
|
delete msg.schema;
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
} else {
|
} else {
|
||||||
msg.schemaError = this.compiledSchema.errors;
|
msg.schemaError = this.compiledSchema.errors;
|
||||||
@ -104,6 +107,7 @@ module.exports = function(RED) {
|
|||||||
// If node.action is obj and value is object
|
// If node.action is obj and value is object
|
||||||
if (validate) {
|
if (validate) {
|
||||||
if (this.compiledSchema(value)) {
|
if (this.compiledSchema(value)) {
|
||||||
|
delete msg.schema;
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
} else {
|
} else {
|
||||||
msg.schemaError = this.compiledSchema.errors;
|
msg.schemaError = this.compiledSchema.errors;
|
||||||
|
@ -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});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user