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

Support $data keyword in $ref #2314

Open
carlo-quinonez opened this issue Jul 28, 2023 · 0 comments
Open

Support $data keyword in $ref #2314

carlo-quinonez opened this issue Jul 28, 2023 · 0 comments

Comments

@carlo-quinonez
Copy link
Contributor

carlo-quinonez commented Jul 28, 2023

What version of Ajv you are you using?
v8.12

What problem do you want to solve?
Validate messages with dynamic subschemas.

Our systems process many different kinds of event with different schemas. However, all the events are packaged into a single envelope. Roughly, the envelope looks like this:

{  // envelope
  "payload" : {  // payload
    // the actual event data is in here
  },
  "payloadSchema": "", // this is the $id of the payload's expected schema
  // additional envelope data like timestamps, source system, etc
}

We want to be able to validate the entire event (both the envelope and payload) in one shot. Right now, we have to validate the event stages. First we validate the envelope, then the code validates payload using the schema indicated in payloadSchema

In addition, a subset of the events also have nested payload, which requires

{  // envelope
  "payload" : {  // payload for a "run" event
     "data" : { // run data 
      },
     "dataSchema" : "" // this is the $id of the run data's expected schema
      // additional run data like runId, user, etc
  },
  "payloadSchema": "", // this is the $id of the payload's expected schema
  // additional envelope data like timestamps, source system, etc
}

I wanted to use the $data keyword to write a schema

{  // envelope schema
  "type" : "object"
  "payload" : { 
    "$ref" :  {
      "$data" : "/payloadSchema" // JSONPointer to the payloadSchema property
    },
  },
  "payloadSchema": {
    "type", "string"
  }
}

For the run schema

{  // run schema
  "type" : "object"
  "data" : { 
    "$ref" :  {
      "$data" : "/dataSchema" // JSONPointer to the dataSchema property
      },
  },
  "dataSchema": {
    "type", "string"
  }
}

However, the $ref keyword does not currently support $data.

What do you think is the correct solution to problem?
Support usage of $data in $ref keyword.

Will you be able to implement it?
We have resources to implement but need guidance. I've looked over the code, but unsure where to start.

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

No branches or pull requests

1 participant