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

schemaReferenced in ValidationListener not returning the proper location #255

Open
afranzi opened this issue Jan 7, 2019 · 4 comments
Open

Comments

@afranzi
Copy link
Contributor

afranzi commented Jan 7, 2019

It seems that from version 1.10.0 to the hash commit 5722c0f4a1306705a56a4d9c11c82bb5709cc57a some behaviour about how the SchemaReferenced works changed.

In the 1.10.0 the SchemaReferenced was returning the location of the schema referenced:

override def schemaReferenced(event: SchemaReferencedEvent): Unit = {
    event.getReferredSchema.getSchemaLocation == "#/allOf/0/properties/product"
}

Now, it's returning the schema Id

    event.getReferredSchema.getSchemaLocation == "/schemas/objects/Product/1.json"

I've been trying to figure out where was the change, but I didn't manage to found it.

The event, I'm validating is

{
  "user": {
    "id": "5a34008f8cece4000764cd5a"
  },
  "device": {
    "id": "5a34008f8cece4000764cd5a",
    "platform": "Android"
  },
  "product": {
    "id": "remixprototype",
    "version": "0.0.1"
  },
  "deploymentEnv": "prod",
  "createdAt":"2018-07-19T13:37:28+02:00",
  "schema": "/schemas/events/device-sensor-event/1.json",
  "source": "sensor",
  "data": {
    "type": "light",
    "level": 0.8
  }
}

And the schema is

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "/schemas/events/base-event/1.json",
  "additionalProperties": true,
  "description": "Base schema for all user-generated events (on device)",
  "properties": {
    "user": {
      "description": "User information",
      "$ref": "/schemas/objects/User/1.json"
    },
    "product": {
      "description": "Product information",
      "$ref": "/schemas/objects/Product/1.json"
    },
    "deploymentEnv": {
      "description": "Deployment environment in use",
      "enum": [
        "dev",
        "test",
        "stage",
        "prod"
      ]
    },
    "createdAt": {
      "description": "Timestamp when the event was generate (following rfc 3339 format)",
      "type": "string",
      "format": "date-time"
    },
    "schema": {
      "description": "Name of the schema to validate against",
      "type": "string"
    },
    "source": {
        "description": "Source of the data point",
        "type": "string",
        "enum": ["sensor", "questionnaire"]
    }
  },
  "required": [
    "source",
    "schema",
    "user",
    "product",
    "deploymentEnv",
    "createdAt"
  ],
  "type": "object"
}
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "/schemas/events/device-sensor-event/1.json",
  "additionalProperties": true,
  "allOf": [
    {
      "$ref": "/schemas/events/base-event/1.json"
    }
  ],
  "description": "User event including sensor data",
  "properties": {
    "data": {
      "oneOf": [
        {"$ref": "/schemas/objects/sensors/SensorAccelerometer/1.json"},
        {"$ref": "/schemas/objects/sensors/SensorActivity/1.json"},
...
        {"$ref": "/schemas/objects/sensors/SensorWalk/1.json"},
        {"$ref": "/schemas/objects/sensors/SensorWifi/1.json"}
      ]
    }
  },
  "required": [
    "data",
    "device",
    "product",
    "user"
  ]
}
@afranzi
Copy link
Contributor Author

afranzi commented Jan 8, 2019

This behavior change seems related with the issue #233, regarding how the ReferenceLookup is being calculated.

https://github.com/everit-org/json-schema/blob/master/core/src/main/java/org/everit/json/schema/loader/ReferenceLookup.java#L164

                .pointerToCurrentObj(SchemaLocation.parseURI(absPointerString))```
    SchemaLoader childLoader = ls.initChildLoader()
            .pointerToCurrentObj(SchemaLocation.parseURI(absPointerString))
            .resolutionScope(!isInternal ? withoutFragment(absPointerString) : ls.id)
            .schemaJson(result.getQueryResult())
            .rootSchemaJson(result.getContainingDocument()).build();

@erosb
Copy link
Contributor

erosb commented Jan 13, 2019

Hello @afranzi can you please check if event.schema.getSchemaLocation fits your needs? In case of SchemaReferencedEvent instances it will be the location of the reference (ReferenceSchema) itself.

Your PR unfortunately can't be merged because it breaks the existing API. 1.10.0 has already been released and you might not be the only one implementing listeners, so we shouldn't change the signature of visit* methods.

@afranzi
Copy link
Contributor Author

afranzi commented Mar 14, 2019

Hi @erosb,

I wanted to share how are we using the JSON-Schemas to Validate, Evolve and anonymize the data.
The Datum VEA - Validate, Evolve and Anonymize your data with Data Schemas

@erosb
Copy link
Contributor

erosb commented Mar 14, 2019

Awesome. Thanks for sharing!

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

No branches or pull requests

2 participants