{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://stac-extensions.github.io/cf/v1.0.0/schema.json#",
  "title": "Climate and Forecasting Convention Extension",
  "description": "STAC CF Extension for STAC Items and STAC Collections.",
  "type": "object",
  "required": ["stac_extensions", "type"],
  "properties": {
    "stac_extensions": {
      "type": "array",
      "contains": {
        "const": "https://stac-extensions.github.io/cf/v1.0.0/schema.json"
      }
    },
    "type": {
      "$comment": "List the allowed STAC object types here, any of: Catalog, Collection, Feature (for Items)",
      "type": "string",
      "enum": [
        "Collection",
        "Feature"
      ]
    },
    "assets": {
      "$comment": "This validates the fields in Item Assets, but does not require them.",
      "type": "object",
      "additionalProperties": {
        "$ref": "#/definitions/fieldsAndOtherContainers"
      }
    },
    "assetTemplates": {
      "$comment": "This validates the fields in asset templates, remove this if not applicable.",
      "type": "object",
      "additionalProperties": {
        "$ref": "#/definitions/fieldsAndOtherContainers"
      }
    }
  },
  "oneOf": [
    {
      "$comment": "This validates the fields in the item properties, remove this if not applicable.",
      "type": "object",
      "required": ["type", "properties"],
      "properties": {
        "type": {
          "const": "Feature"
        },
        "properties": {
          "$ref": "#/definitions/fieldsAndOtherContainers"
        }
      }
    },
    {
      "$comment": "This is the schema for top-level fields and item assets in STAC Collections, remove this fully or in parts if not applicable.",
      "type": "object",
      "required": ["type"],
      "properties": {
        "type": {
          "const": "Collection"
        },
        "summaries": {
          "$ref": "#/definitions/summaries"
        },
        "item_assets": {
          "$comment": "This validates the fields in item assets, remove this if not applicable.",
          "type": "object",
          "additionalProperties": {
            "$ref": "#/definitions/fieldsAndOtherContainers"
          }
        }
      },
      "allOf": [
        {
          "$ref": "#/definitions/fieldsAndOtherContainers"
        }
      ]
    }
  ],
  "definitions": {
    "cf:standard_name": {
      "type": "string",
      "minLength": 1
    },
    "cf:cell_methods": {
      "type": "array",
      "items": {
        "type": ["string", "null"]
      }
    },
    "description": {
      "type": "string",
      "minLength": 1
    },
    "unit": {
      "type": "string"
    },
    "fields": {
      "type": "object",
      "properties": {
        "cf:standard_name": {
          "$ref": "#/definitions/cf:standard_name"
        },
        "cf:cell_methods": {
          "$ref": "#/definitions/cf:cell_methods"
        },
        "description": {
          "$ref": "#/definitions/description"
        },
        "unit": {
          "$ref": "#/definitions/unit"
        }
      },
      "patternProperties": {
        "^(?!cf:)": {}
      },
      "additionalProperties": false
    },
    "fieldsAndOtherContainers": {
      "allOf": [
        {
          "$ref": "#/definitions/fields"
        },
        {
          "properties": {
            "bands": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/fields"
              }
            }
          }
        },
        {
          "properties": {
            "cube:dimensions": {
              "type": "object",
              "additionalProperties": {
                "$ref": "#/definitions/fields"
              }
            }
          }
        },
        {
          "properties": {
            "cube:variables": {
              "type": "object",
              "additionalProperties": {
                "$ref": "#/definitions/fields"
              }
            }
          }
        }
      ]
    },
    "summaries": {
      "$comment": "These are examples summaries that allows lists, ranges and JSON schemas, depending on how it makes sense for the individual data types of the fields. Validation only works for lists and ranges. JSON Schema (type: object) can always be provided for fields, but the corresponding schema for lists (type: array and items) and ranges (properties) should only be provided if it actually makes sense.",
      "type": "object",
      "properties": {
        "cf:standard_name": {
          "type": ["array", "object"],
          "uniqueItems": true,
          "items": {
            "$ref": "#/definitions/cf:standard_name"
          }
        },
        "cf:cell_methods": {
          "type": ["array", "object"],
          "uniqueItems": true,
          "items": {
            "$ref": "#/definitions/cf:cell_methods"
          }
        }
      },
      "patternProperties": {
        "^(?!cf:)": {}
      },
      "additionalProperties": false
    }
  }
}
