Skip to content

Commit 96417be

Browse files
committed
Simplified flow
1 parent dbad6e5 commit 96417be

8 files changed

+13
-17
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Here is an example of full Node-RED flow: [Node-RED_example_of_flow.json](exampl
3030
* *Purpose*: Ability to determine the URL of the JSON Schema (e.g. FIWARE NGSI) or JSONata expression to use for a given JSON payload received.
3131
* *Configuration*: A Node-RED `mappingsUrl` property to indicate the URL of a file listing which JSON Schema or JSONata expression to use for which data input. (See examples below).
3232
* *Input*: A JSON observation (e.g. one of the FIWARE NGSI types) in the `msg.payload` property.
33-
* *Output*: The unmodified JSON observation in the `msg.payload` property, and the resolved schema URL in the `msg.schemaUrl` property.
33+
* *Output*: The unmodified JSON observation in the `msg.payload` property, and the resolved schema URL in the `msg.schemaUrl` property (if any match was found).
3434

3535
### Example of input data
3636
This is an example of [standard payload](https://fiware-datamodels.readthedocs.io/en/latest/Transportation/Vehicle/Vehicle/doc/spec/index.html), for which we need to look-up the [corresponding JSON Schema](https://smart-data-models.github.io/data-models/specs/Transportation/Vehicle/VehicleModel/schema.json).
@@ -166,7 +166,8 @@ Output:
166166
* *Context*: Node-RED node, or command line with `index.js multi-schema-transformer`
167167
* *Purpose*: Ability to transform a JSON observation on the fly from whichever format to another format (e.g. one of the FIWARE NGSI types) using a specified JSONata URL. Schemas are automatically downloaded and cached the first time they are needed.
168168
* *Input*: A JSON observation in whichever format in the `msg.payload` property, and the corresponding JSONata URL on the `msg.schemaUrl` property (coming from json-multi-schema-resolver).
169-
* *Output*: The transformed JSON observation in the `msg.payload` property, and potential validation errors in the `msg.error` property.
169+
* If no `msg.schemaUrl` is provided, no transformation is performed.
170+
* *Output*: The transformed JSON observation in the `msg.payload` property, the used JSONata in the `msg.transformUrl` (if any transformation was performed), and potential validation errors in the `msg.error` property.
170171
* *Implementation*: Based on [JSONata](https://github.com/jsonata-js/jsonata).
171172

172173
It is typically used with a *json-multi-schema-resolver* node in front.
@@ -261,7 +262,8 @@ Output:
261262
* *Context*: Node-RED node, or command line with `./index.js json-multi-schema-validator`
262263
* *Purpose*: Ability to validate a JSON observation (e.g. one of the FIWARE NGSI types) on the fly against a specified JSON Schema URL. Schemas are automatically downloaded and cached the first time they are needed.
263264
* *Input*: A JSON observation (e.g. one of the FIWARE NGSI types) in the `msg.payload` property, and the corresponding JSON Schema URL on the `msg.schemaUrl` property (coming from json-multi-schema-resolver).
264-
* *Output*: The unmodified JSON observation in the `msg.payload` property, and potential validation errors in the `msg.error` property.
265+
* If no `msg.schemaUrl` is provided, no validation is performed.
266+
* *Output*: The unmodified JSON observation in the `msg.payload` property, the used schema in the `msg.validUrl` (if any validation was performed), and potential validation errors in the `msg.error` property.
265267
* *Implementation*: Based on [AJV](https://ajv.js.org).
266268

267269
It is typically used with a *json-multi-schema-resolver* node in front.

json-multi-schema-resolver.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ module.exports = RED => {
5454
if (schemaUrl != '') {
5555
msg.schemaUrl = schemaUrl;
5656
msg.error = msg.error != '';
57-
} else {
58-
msg.error += util.format('Failed resolving schema using "%s"', mappingsUrl);
5957
}
6058
if (lastStatusError) {
6159
node.status({ fill:'green', shape:'dot', text:'OK', });

json-multi-schema-transformer.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
<p>Node to transform a JSON observation to another format using a configurable set of JSONata rules.</p>
2626
<ul>
2727
<li>The node will transform a given JSON payload received in <code>msg.payload</code> using some JSONata rules, which URL is given in <code>msg.schemaUrl</code></li>
28-
<li>The URL of the corresponding JSONata file is returned in <code>msg.transformUrl</code>.</li>
29-
<li>The transformed payload is returned in <code>msg.payload</code>.</li>
28+
<li>If any transformation is actually performed, the URL of the corresponding JSONata file is returned in <code>msg.transformUrl</code>.</li>
29+
<li>The transformed payload is returned in <code>msg.payload</code>. If no <code>msg.schemaUrl</code> is provided, no transformation is performed.</li>
3030
<li>Errors are returned on <code>msg.error</code></li>
3131
</ul>
3232
<p>Example of file containing the list of transformations:</p>

json-multi-schema-transformer.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ module.exports = RED => {
6666

6767
node.on('input', async msg => {
6868
msg.error = msg.error ? msg.error + ' ; ' : '';
69-
if (msg.schemaUrl == '') {
70-
msg.error += 'Unknown schema!';
71-
} else {
69+
if (msg.schemaUrl != '') {
7270
msg.transformUrl = msg.schemaUrl;
7371
try {
7472
const result = await transformAsync(msg.payload, msg.schemaUrl);

json-multi-schema-validator.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
<script type="text/x-red" data-help-name="json-multi-schema-validator">
2525
<ul>
2626
<li>The node will validate the JSON data given in <code>msg.payload</code> against the JSON Schema URL given in <code>msg.schemaUrl</code></li>
27-
<li>The URL of the corresponding JSON Schema file is returned in <code>msg.validUrl</code>.</li>
28-
<li>The content of <code>msg.payload</code> is unchanged.</li>
27+
<li>If any validation was actually performed, the URL of the corresponding JSON Schema file is returned in <code>msg.validUrl</code>.</li>
28+
<li>The content of <code>msg.payload</code> is unchanged. If no <code>msg.schemaUrl</code> is provided, no validation is performed.</li>
2929
<li>Errors are returned on <code>msg.error</code></li>
3030
</ul>
3131
</script>

json-multi-schema-validator.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ module.exports = RED => {
9090

9191
node.on('input', async msg => {
9292
msg.error = msg.error ? msg.error + ' ; ' : '';
93-
if (msg.schemaUrl == '') {
94-
msg.error += 'Unknown schema!';
95-
} else {
93+
if (msg.schemaUrl != '') {
9694
msg.validUrl = msg.schemaUrl;
9795
try {
9896
const result = await validateAsync(msg.payload, msg.schemaUrl);

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-contrib-json-multi-schema",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "Generic JSON data pipeline tools, with dynamic transformation (using JSONata rules), resolving JSON Schema (using JSONata rules), and then validation (using JSON Schema). For Node-RED and for command-line.",
55
"main": "index.js",
66
"readmeFilename": "readme.md",

0 commit comments

Comments
 (0)