How can I validate a json pointer for a given Json Schema (even with $ref fields)?

776 Views Asked by At

I am working with a JsonSchema that utilizes nested data structures where I use $ref for some properties and for others I just write in the data structures (no $ref). Basically I have to consider many types of JsonSchema Structures.

What I am trying to do is, given a list of Json Pointers, I want to validate that all the Json Pointer Expressions are valid properties existing in the Schema. The Json Pointer Expressions can be nested as well. Here is an example:

product.schema.json

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.com/product.schema.json",
  "title": "Product",
  "description": "A product from Acme's catalog",
  "type": "object",
  "properties": 
    "dimensions": {
      "type": "object",
      "properties": {
        "length": {
          "type": "number"
        },
        "width": {
          "type": "number"
        },
        "height": {
          "type": "number"
        }
      }
    },
    {
    "warehouseLocation": {
      "description": "Coordinates of the warehouse where the product is located.",
      "$ref": "https://example.com/geographical-location.schema.json"
    }
  }
}

geographical-location.schema.json

{
  "$id": "https://example.com/geographical-location.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Longitude and Latitude",
  "description": "A geographical coordinate on a planet (most commonly Earth).",
  "type": "object",
  "properties": {
    "latitude": {
      "type": "number"
    },
    "longitude": {
      "type": "number"
    }
  }
}

The above JsonSchema has the two types of nested schema structures. Lets say give these Schema, I also am give a list of JsonPtrExps:

["/dimensions/length", "/warehouseLocation/longitude", "/dimensions/mass"]

I am trying to find a way to use the schema to predict and validate which of the JsonPointerExpressions would return a valid property. "/dimensions/length", "/warehouseLocation/longitude" would pass this validation but "/dimensions/mass" would not.

Also I would like to be able to make this decisions went I am only reading the product.schema.json even though I can access geographical-location.schema.json by using the $ref field.

Any thoughts?

0

There are 0 best solutions below