We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Does JSON Validator support JSON Schema draft 7?

Does JSON Validator support JSON Schema draft 7?

MichaelDM
Shopify Partner
1 0 0

Hello folks, 

I've created a metafield for a product, and have added the schema below: 

{
  "title": "Metafield Information",
  "description": "This details how a metafield information is structured",
  "type": "object",
  "properties": {
    "option_values": {
      "type": "array",
      "description": "List of option values",
      "items": {
        "type": "object",
        "properties": {
          "associated_option_name": {
            "type": "string",
            "description": "The exact name of the option",
            "enum":[
              "Modèles", 
              "Installation", 
              "Modification",
              "Tailles",
              "Couleurs",
              "Modèle neuf",
              "Assurance",
              "SAV"
           ]
          },
          "title": {
            "type": "string",
            "description": "The option value title"
          },
          "subtitle": {
            "type": "string",
            "description": "The option value subtitle"
          },
          "price": {
            "type": "number",
            "description": "The option value price with decimals"
          },
          "color": {
            "type": "string",
            "description": "The option value color swab"
          }
        },
        "required": ["associated_option_name", "title"],
        "allOf": [
          {
            "if": {
              "properties": { "associated_option_name": { "const": "Modèles" } },
              "required": ["associated_option_name"]
            },
            "then": {
              "required": ["subtitle", "price"]
            }
          },
          {
            "if": {
              "properties": { "associated_option_name": { "const": "Installation" } },
              "required": ["associated_option_name"]
            },
            "then": {
              "required": ["price"]
            }
          },
          {
            "if": {
              "properties": { "associated_option_name": { "const": "Modification" } },
              "required": ["associated_option_name"]
            },
            "then": {
              "required": ["price"]
            }
          },
          {
            "if": {
              "properties": { "associated_option_name": { "const": "Tailles" } },
              "required": ["associated_option_name"]
            },
            "then": {
              "required": ["subtitle"]
            }
          },
          {
            "if": {
              "properties": { "associated_option_name": { "const": "Couleurs" } },
              "required": ["associated_option_name"]
            },
            "then": {
              "required": ["color"]
            }
          },
          {
            "if": {
              "properties": { "associated_option_name": { "const": "Modèle neuf" } },
              "required": ["associated_option_name"]
            },
            "then": {
              "required": ["price"]
            }
          },
          {
            "if": {
              "properties": { "associated_option_name": { "const": "Assurance" } },
              "required": ["associated_option_name"]
            },
            "then": {
              "required": ["price"]
            }
          },
          {
            "if": {
              "properties": { "associated_option_name": { "const": "SAV" } },
              "required": ["associated_option_name"]
            },
            "then": {
              "required": ["price"]
            }
          }
        ]
      }
    }
  },
  "required": ["option_values"]
}


{
  "option_values": [
    {
      "associated_option_name": "Modèles", 
      "title": "20 km d'autonomie",
      "subtitle": "Puissance de 350 W",
      "price": 0,
      "color": "black"
    }
  ]
}


When I use the following JSON in the product metafield, my product saves and DOES NOT throw back an error on the metafield.

{
  "option_values": [
    {
      "associated_option_name": "Modèles", 
      "title": "20 km d'autonomie",
      "subtitle": "Puissance de 350 W",
      "color": "black",
    }
  ]
}


Since "associated_option_name" is equal to "Modèles" and property "price" is non-existent, I had expected an error saying that price is required. 

If I use the same code and test it on https://www.jsonschemavalidator.net/, I do get back the expected error. But if I change draft 7 to draft 4 (http://json-schema.org/draft-04/schema#), I no longer get an error, because the if/then statements are new additions. 

Although I have specified the schema, is Shopify somehow overriding it with is own version of json-schema? 
Is there a way for me to use draft 7? (or > draft 4) 

 

Replies 0 (0)