{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://catalog.lintel.tools/schemas/schemastore/libman-json/latest.json",
  "title": "JSON schema for client-side library config files",
  "x-lintel": {
    "source": "https://www.schemastore.org/libman.json",
    "sourceSha256": "ea358b97892b961f476e30e0dceca57a1659110a3ad989b806fca9a82687518c",
    "fileMatch": [
      "libman.json"
    ],
    "parsers": [
      "json"
    ]
  },
  "type": "object",
  "properties": {
    "libraries": {
      "description": "A list of library references.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/libraryEntry"
      }
    },
    "version": {
      "description": "The syntax version of this config file.",
      "enum": [
        "1.0",
        "3.0"
      ],
      "default": "3.0"
    }
  },
  "required": [
    "libraries",
    "version"
  ],
  "$defs": {
    "libraryEntry": {
      "required": [
        "library"
      ],
      "properties": {
        "files": {
          "description": "The file names of the individual files to copy to the project.",
          "type": "array",
          "default": null,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "library": {
          "description": "The unique identifier of the library.",
          "type": "string",
          "minLength": 1
        },
        "destination": {
          "description": "The relative folder path from this config file to the location where the files should be copied to.",
          "type": "string",
          "pattern": "^[^\\\\]+$"
        },
        "provider": {
          "description": "The unique identifier of the provider",
          "type": "string",
          "minLength": 1
        },
        "fileMappings": {
          "description": "A list of file mappings.",
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "root": {
                "description": "The mapping root within the library contents. If omitted, defaults to the library root.",
                "type": "string",
                "minLength": 1
              },
              "destination": {
                "description": "The destination for files included in this mapping. If omitted, defaults to a destination set for the library.",
                "type": "string",
                "minLength": 1
              },
              "files": {
                "description": "The file names of the individual files to copy to the project, relative to the specified root. If omitted, defaults to all files.",
                "type": "array",
                "default": null,
                "items": {
                  "type": "string",
                  "minLength": 1
                }
              }
            }
          }
        }
      },
      "type": "object"
    },
    "specifiedProvider": {
      "properties": {
        "libraries": {
          "items": {
            "required": [
              "provider"
            ]
          }
        }
      },
      "not": {
        "required": [
          "defaultProvider"
        ]
      },
      "type": "object"
    },
    "defaultProvider": {
      "properties": {
        "defaultProvider": {
          "description": "The unique identifier of the provider to use as default.",
          "type": "string",
          "minLength": 1
        }
      }
    },
    "specifiedDestination": {
      "properties": {
        "libraries": {
          "items": {
            "required": [
              "destination"
            ]
          }
        }
      },
      "not": {
        "required": [
          "defaultDestination"
        ]
      },
      "type": "object"
    },
    "defaultDestination": {
      "properties": {
        "defaultDestination": {
          "description": "The default destination to place library files.",
          "type": "string",
          "minLength": 1
        }
      }
    },
    "fileMapping": {
      "properties": {
        "libraries": {
          "contains": {
            "required": [
              "fileMappings"
            ]
          }
        }
      }
    },
    "manifestVersion3": {
      "properties": {
        "version": {
          "const": "3.0"
        }
      },
      "required": [
        "version"
      ],
      "type": "object"
    }
  },
  "allOf": [
    {
      "anyOf": [
        {
          "$ref": "#/$defs/specifiedProvider"
        },
        {
          "$ref": "#/$defs/defaultProvider"
        }
      ]
    },
    {
      "anyOf": [
        {
          "$ref": "#/$defs/specifiedDestination"
        },
        {
          "$ref": "#/$defs/defaultDestination"
        }
      ]
    },
    {
      "if": {
        "$ref": "#/$defs/fileMapping"
      },
      "then": {
        "$ref": "#/$defs/manifestVersion3"
      }
    }
  ]
}
