JSON Node - Schema validation - ID problem

Hey,

finally i found the root cause of this topic's problem. But the thread is closed :frowning:

JSON Node - Schema validation

The reason why i couldn't validate a schema with $id more than once is the missing option in the AJV library.
https://ajv.js.org/options.html#addusedschema

With this option it's possible to validate a json schema more than once against other schemata. :slight_smile:

Hi - in the v2-beta Nick has merged an update for AJV - Merge pull request #2969 from node-red/ajv-update · node-red/node-red@3d405f8 · GitHub - does this help the problem or is something else missing ?

Hey dceejay,

I think it should be

const ajv = new Ajv({allErrors: true, addUsedSchema: false});

This allows it to validate json which can also be a schema which contains $id more than once.
I could try to create a merge request and an example flow demonstrating this monday evening :slight_smile:

Sorry i did not found enough time yet to do it.
This would be my first open source contribution in form of code. Do you maybe have a guideline for this @dceejay?
EDIT -> i found it node-red/CONTRIBUTING.md at master · node-red/node-red · GitHub

here is a problematic flow. An example schema copied from json-schema.org

[{"id":"86ca646.c79ea98","type":"json","z":"38d6b820.063658","name":"","property":"payload","action":"obj","pretty":false,"x":490,"y":180,"wires":[["1d7c6628.6d1f6a"]]},{"id":"dc23685b.c41e38","type":"inject","z":"38d6b820.063658","name":"","props":[{"p":"payload"},{"p":"schema","v":"{\"$id\":\"https://example.com/geographical-location.schema.json\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"title\":\"Longitude and Latitude Values\",\"description\":\"A geographical coordinate.\",\"required\":[\"latitude\",\"longitude\"],\"type\":\"object\",\"properties\":{\"latitude\":{\"type\":\"number\",\"minimum\":-90,\"maximum\":90},\"longitude\":{\"type\":\"number\",\"minimum\":-180,\"maximum\":180}}}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"latitude\": 90, \"longitude\":180}","payloadType":"json","x":340,"y":180,"wires":[["86ca646.c79ea98"]]},{"id":"1d7c6628.6d1f6a","type":"debug","z":"38d6b820.063658","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":180,"wires":[]}]

When i try to checkout the branch ajv-update
and executing

npm install
npm run build
npm start

The browser is not responding on localhost:1880
The master branch is working for me. Did i miss something ?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.