{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://raw.githubusercontent.com/tscnlab/glc-metadata-validator/main/schemas/3.0.2/glc-dp-profile.json",
  "name": "glc-dp-profile",
  "title": "GLC Data Package Profile",
  "description": "Frictionless profile for GLC data packages. Requires core resources and allows additional resources.",
  "version": "3.0.2",
  "type": "object",
  "allOf": [
    {
      "$ref": "https://specs.frictionlessdata.io/schemas/data-package.json"
    },
    {
      "type": "object",
      "required": [
        "resources",
        "profile",
        "schema_version"
      ],
      "properties": {
        "schema_version": {
          "type": "string",
          "const": "3.0.2",
          "description": "Release version of the GLC metadata standard used by this package.",
          "examples": [
            "3.0.2"
          ]
        },
        "profile": {
          "type": "string",
          "anyOf": [
            {
              "const": "data-package"
            },
            {
              "pattern": "^schemas/3\\.0\\.2/glc-dp-profile\\.json$"
            },
            {
              "pattern": "^glc-dp-profile\\.json$"
            },
            {
              "pattern": "^(https?|file)://.*/glc-dp-profile\\.json$"
            }
          ],
          "description": "Path/URL to the package profile, or the canonical 'data-package' alias.",
          "examples": [
            "https://globallightcommons.org/schemas/3.0.2/glc-dp-profile.json"
          ]
        },
        "resources": {
          "type": "array",
          "minItems": 5,
          "description": "Resources in the data package. Certain core resources are required by this profile; additional resources may be included with any name.",
          "items": {
            "anyOf": [
              {
                "title": "Core resource (canonical name)",
                "type": "object",
                "required": [
                  "name",
                  "path",
                  "profile"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "enum": [
                      "study",
                      "participants",
                      "datasets",
                      "devices",
                      "device_datasheets",
                      "participant_characteristics"
                    ],
                    "description": "Canonical resource name recognized by the GLC profile. Some canonical resources are required; others are optional.",
                    "examples": [
                      "study"
                    ]
                  },
                  "path": {
                    "type": "string",
                    "description": "Path to the resource file (or folder), relative to the datapackage.json.",
                    "examples": [
                      "data/study.json"
                    ]
                  },
                  "profile": {
                    "type": "string",
                    "anyOf": [
                      {
                        "const": "tabular-data-resource"
                      },
                      {
                        "pattern": "^(.*/)?json-entity-resource\\.json$"
                      },
                      {
                        "pattern": "^(https?|file)://.*/json-entity-resource\\.json$"
                      }
                    ]
                  },
                  "format": {
                    "type": "string"
                  },
                  "mediatype": {
                    "type": "string"
                  },
                  "schema": {
                    "type": [
                      "string",
                      "object"
                    ],
                    "description": "Table Schema — for tabular resources only.",
                    "examples": [
                      "schemas/3.0.2/participants.schema.json"
                    ]
                  },
                  "jsonSchema": {
                    "type": "string",
                    "description": "JSON Schema — for non-tabular resources only.",
                    "examples": [
                      "schemas/3.0.2/study.schema.json"
                    ]
                  }
                },
                "allOf": [
                  {
                    "if": {
                      "properties": {
                        "profile": {
                          "const": "tabular-data-resource"
                        }
                      }
                    },
                    "then": {
                      "required": [
                        "schema",
                        "mediatype"
                      ],
                      "properties": {
                        "mediatype": {
                          "enum": [
                            "text/csv",
                            "application/json"
                          ]
                        }
                      }
                    }
                  },
                  {
                    "if": {
                      "properties": {
                        "profile": {
                          "anyOf": [
                            {
                              "pattern": "json-entity-resource\\.json$"
                            },
                            {
                              "pattern": "^(https?|file)://.*/json-entity-resource\\.json$"
                            }
                          ]
                        }
                      }
                    },
                    "then": {
                      "required": [
                        "jsonSchema",
                        "mediatype"
                      ],
                      "properties": {
                        "mediatype": {
                          "const": "application/json"
                        }
                      }
                    }
                  }
                ]
              },
              {
                "title": "Additional resource (any name allowed)",
                "type": "object",
                "required": [
                  "name",
                  "path",
                  "profile"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Name of an additional, non-core resource.",
                    "examples": [
                      "study"
                    ]
                  },
                  "path": {
                    "type": "string"
                  },
                  "profile": {
                    "type": "string",
                    "anyOf": [
                      {
                        "const": "tabular-data-resource"
                      },
                      {
                        "pattern": "^(.*/)?json-entity-resource\\.json$"
                      },
                      {
                        "pattern": "^(https?|file)://.*/json-entity-resource\\.json$"
                      }
                    ]
                  },
                  "format": {
                    "type": "string"
                  },
                  "mediatype": {
                    "type": "string"
                  },
                  "schema": {
                    "type": [
                      "string",
                      "object"
                    ]
                  },
                  "jsonSchema": {
                    "type": "string"
                  }
                },
                "allOf": [
                  {
                    "not": {
                      "properties": {
                        "name": {
                          "enum": [
                            "study",
                            "participants",
                            "datasets",
                            "devices",
                            "device_datasheets",
                            "participant_characteristics"
                          ]
                        }
                      },
                      "required": [
                        "name"
                      ]
                    }
                  },
                  {
                    "if": {
                      "properties": {
                        "profile": {
                          "const": "tabular-data-resource"
                        }
                      }
                    },
                    "then": {
                      "required": [
                        "schema",
                        "mediatype"
                      ],
                      "properties": {
                        "mediatype": {
                          "enum": [
                            "text/csv",
                            "application/json"
                          ]
                        }
                      }
                    }
                  },
                  {
                    "if": {
                      "properties": {
                        "profile": {
                          "anyOf": [
                            {
                              "pattern": "json-entity-resource\\.json$"
                            },
                            {
                              "pattern": "^(https?|file)://.*/json-entity-resource\\.json$"
                            }
                          ]
                        }
                      }
                    },
                    "then": {
                      "required": [
                        "jsonSchema",
                        "mediatype"
                      ],
                      "properties": {
                        "mediatype": {
                          "const": "application/json"
                        }
                      }
                    }
                  }
                ]
              }
            ]
          },
          "allOf": [
            {
              "contains": {
                "properties": {
                  "name": {
                    "const": "study"
                  }
                }
              }
            },
            {
              "contains": {
                "properties": {
                  "name": {
                    "const": "participants"
                  }
                }
              }
            },
            {
              "contains": {
                "properties": {
                  "name": {
                    "const": "datasets"
                  }
                }
              }
            },
            {
              "contains": {
                "properties": {
                  "name": {
                    "const": "devices"
                  }
                }
              }
            },
            {
              "contains": {
                "properties": {
                  "name": {
                    "const": "device_datasheets"
                  }
                }
              }
            }
          ],
          "examples": [
            [
              {
                "name": "study",
                "path": "data/study.json",
                "jsonSchema": "schemas/3.0.2/study.schema.json"
              }
            ]
          ]
        }
      }
    }
  ]
}
