{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://stac-extensions.github.io/grid/v1.1.0/schema.json#",
  "title": "Grid Extension",
  "description": "STAC Grid Extension for STAC Items.",
  "oneOf": [
    {
      "$comment": "This is the schema for STAC Items",
      "allOf": [
        {
          "$ref": "#/definitions/stac_extensions"
        },
        {
          "type": "object",
          "required": [
            "type",
            "properties",
            "assets"
          ],
          "properties": {
            "type": {
              "const": "Feature"
            },
            "properties": {
              "allOf": [
                {
                  "required": [
                    "grid:code"
                  ]
                },
                {
                  "$ref": "#/definitions/fields"
                }
              ]
            }
          }
        }
      ]
    }
  ],
  "definitions": {
    "stac_extensions": {
      "type": "object",
      "required": [
        "stac_extensions"
      ],
      "properties": {
        "stac_extensions": {
          "type": "array",
          "contains": {
            "const": "https://stac-extensions.github.io/grid/v1.1.0/schema.json"
          }
        }
      }
    },
    "require_any_field": {
      "anyOf": [
        {"required": ["grid:code"]}
      ]
    },
    "fields": {
      "type": "object",
      "properties": {
        "grid:code": {
          "type": "string",
          "pattern": "^[A-Z0-9]+-[-_.A-Za-z0-9]+$"
        }
      },
      "patternProperties": {
        "^(?!grid:)": {
          "$comment": "Do not allow other fields with this prefix"
        }
      },
      "additionalProperties": false
    }
  }
}
