RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.37k stars 529 forks source link

Question: Retrieve JSON Schema definition for a Json Element/Node? #1678

Open tthiery opened 5 months ago

tthiery commented 5 months ago

I am building a auditing tool for JSON (basically diff them and use annotations to get meaningful audit entries).

Example

Old Data

        {
            "mode": "foo",
            "config": [
                {
                    "id": "backgroundColor",
                    "value": "green"
                }
            ]
        }

New Data

        {
            "mode": "foo",
            "config": [
                {
                    "id": "backgroundColor",
                    "value": "red"
                }
            ]
        }

producing a audit representation as

Setting 'Background Color' > Configuration changed from 'Green' to 'Redish'

I identify the change and have a stack available where the change happens.

I am currently working with a hierarchical annotation (which specify property, key, value, type mappings) model but this becomes equally complex as a schema in the end. Right now it still works since my JSON modelling is quite ... simplistic (object, arrays, Keyed Array, Polymorphic Array). But I would love to put it on a solid ground.

The idea I am exploring is to extend my JSON Schema definitions with private properties (for my auditing purpose) and then fetch that definition whenever I operate on the related nodes.

Question

Is there a way in the NJsonSchema API to look up the schema definition for a given node (stack)? (like a visitor pattern, a helper function, ...)