Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Schema validation path traceability #256

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

afranzi
Copy link
Contributor

@afranzi afranzi commented Jan 9, 2019

This PR aims to show a PoC of tracing how the schema is being validated, that means which subschemas are being validated regarding the location of them.

The example from https://gist.github.com/afranzi/76497177ea8bc305c355b49bc3b2f6b0 shows how we are using a complex schema to validate one SensorEvent. After validating we generate the following output:

// Output after validating the 1.device-sensor-wifi-event.json
SchemaReferenced("#/device", "/schemas/objects/Device/1.json")
SchemaReferenced("#/product","/schemas/objects/Product/1.json")
SchemaReferenced("#/user","/schemas/objects/User/1.json")
SchemaReferenced("#","/schemas/events/base-event/1.json")
SchemaReferenced("#","/schemas/events/base-device-event/1.json")
SchemaReferenced("#/data/scan/[0]","/schemas/objects/sensors/WifiConnection/1.json")
SchemaReferenced("#/data/scan/[1]","/schemas/objects/sensors/WifiConnection/1.json")
SchemaReferenced("#/data","/schemas/objects/sensors/SensorWifi/1.json")

Then we know that this event was formed by a SensorWifi data inside the #/data field and then inside that one the array #/data/scan contains two elements that validates agains the WifiConnection schema. Knowing which schema validates each item matters if the array of items can contain different types of subschemas.

I'm not really proud of this solution by passing all the paths through the accept and validate methods. So I would be open to any advice, proposal, idea, best practise to improve it.

What do you think @erosb? You can see in the Gist how are we using the ValidationListener.

Thanks,
Regards,

@coveralls
Copy link

coveralls commented Jan 9, 2019

Coverage Status

Coverage decreased (-0.6%) to 90.009% when pulling 7785521 on afranzi:validation-path into 5722c0f on everit-org:master.

@erosb
Copy link
Contributor

erosb commented Jan 9, 2019

Hello @afranzi how is this newly introduced path different from the existing Schema#getSchemaLocation() (which is computed during schema loading and also available in visitor methods)?

@afranzi
Copy link
Contributor Author

afranzi commented Jan 9, 2019

Hi @erosb, this is different from the schemaLocation change that I saw in the issue #233 and also referenced in the issue #255.

If I understand properly, it seems that the schemaLocation is returning the absolute pointer of the schema, so it's the resolution to define where the schema is located, but not where from the validated event is the subschema being validated.

@afranzi
Copy link
Contributor Author

afranzi commented Jan 14, 2019

Hi @erosb,

Using the Schema#getSchemaLocation() it returns the following from the SchemaReferenced Event

SchemaReferenced(/schemas/objects/sensors/WifiConnection/1.json,/schemas/objects/sensors/WifiConnection/1.json)
SchemaReferenced(/schemas/objects/sensors/SensorWifi/1.json,/schemas/objects/sensors/SensorWifi/1.json)
SchemaReferenced(/schemas/objects/Device/1.json,/schemas/objects/Device/1.json)
SchemaReferenced(/schemas/objects/Product/1.json,/schemas/objects/Product/1.json)
SchemaReferenced(/schemas/objects/User/1.json,/schemas/objects/User/1.json)
SchemaReferenced(/schemas/events/base-event/1.json,/schemas/events/base-event/1.json)
SchemaReferenced(/schemas/events/base-device-event/1.json,/schemas/events/base-device-event/1.json)

As you can see, it returns the schema location, but not the exact path in the event validated where the subschema was matching.

Regarding your comment in the issue #255 (comment), which proposal or workaround would you propose to get the correct path?

@erosb
Copy link
Contributor

erosb commented Jan 14, 2019

Hello @afranzi ,

thinking through it, regarding both your open issues, I think the best I can advise you is keeping up a permanent fork of the library (at least for the duration of your project), altering it in the way you need to. Then when you are done with your project we will see what added features can we backport into this repository.

From my view the situation is that you are using the library for something that it isn't really designed for, and in a way that I don't clearly understand. No doubt it sounds like an awesome research project, but I simply don't have the mental capacity these times to understand it, hence it is hard to advise on design in a forward-thinking way.

Thank you for your understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants