{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://flow.jig.md/schemas/capability-contract-1.schema.json",
  "title": "FLOW Capability Contract/1 descriptor",
  "type": "object",
  "properties": {
    "$schema": {
      "const": "https://flow.jig.md/schemas/capability-contract-1.schema.json"
    },
    "flowCapabilityContract": {
      "const": 1
    },
    "id": {
      "$ref": "#/$defs/contractId"
    },
    "version": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
    },
    "methods": {
      "type": "object",
      "propertyNames": {
        "$ref": "#/$defs/localName"
      },
      "additionalProperties": {
        "$ref": "#/$defs/method"
      },
      "minProperties": 1,
      "maxProperties": 256
    },
    "$defs": {
      "type": "object",
      "propertyNames": {
        "$ref": "#/$defs/definitionName"
      },
      "additionalProperties": {
        "$ref": "#/$defs/flowSchema"
      },
      "maxProperties": 1024
    }
  },
  "required": [
    "$schema",
    "flowCapabilityContract",
    "id",
    "version",
    "methods"
  ],
  "additionalProperties": false,
  "$defs": {
    "contractId": {
      "type": "string",
      "pattern": "^https://(?!(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])(?:/|$))[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+/(?!\\.{1,2}(?:/|$))[a-z0-9._~-]+(?:/(?!\\.{1,2}(?:/|$))[a-z0-9._~-]+)*$"
    },
    "localName": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$",
      "maxLength": 64
    },
    "definitionName": {
      "type": "string",
      "pattern": "^[A-Za-z][A-Za-z0-9]{0,63}$"
    },
    "method": {
      "type": "object",
      "properties": {
        "input": {
          "$ref": "#/$defs/flowSchema"
        },
        "output": {
          "$ref": "#/$defs/flowSchema"
        },
        "errors": {
          "type": "object",
          "propertyNames": {
            "$ref": "#/$defs/localName"
          },
          "additionalProperties": {
            "$ref": "#/$defs/flowSchema"
          },
          "maxProperties": 128
        }
      },
      "required": [
        "input",
        "output",
        "errors"
      ],
      "additionalProperties": false
    },
    "jsonScalar": {
      "type": [
        "null",
        "boolean",
        "number",
        "string"
      ]
    },
    "schemaArray": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/flowSchema"
      },
      "minItems": 1
    },
    "stringArray": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "uniqueItems": true
    },
    "flowSchema": {
      "oneOf": [
        {
          "type": "boolean"
        },
        {
          "$ref": "#/$defs/schemaObject"
        }
      ]
    },
    "schemaObject": {
      "type": "object",
      "properties": {
        "$ref": {
          "type": "string",
          "pattern": "^#/\\$defs/[A-Za-z][A-Za-z0-9]{0,63}$"
        },
        "$comment": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "examples": {
          "type": "array"
        },
        "type": {
          "oneOf": [
            {
              "enum": [
                "array",
                "boolean",
                "integer",
                "null",
                "number",
                "object",
                "string"
              ]
            },
            {
              "type": "array",
              "items": {
                "enum": [
                  "array",
                  "boolean",
                  "integer",
                  "null",
                  "number",
                  "object",
                  "string"
                ]
              },
              "minItems": 1,
              "maxItems": 7,
              "uniqueItems": true
            }
          ]
        },
        "enum": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/jsonScalar"
          }
        },
        "const": {
          "$ref": "#/$defs/jsonScalar"
        },
        "allOf": {
          "$ref": "#/$defs/schemaArray"
        },
        "anyOf": {
          "$ref": "#/$defs/schemaArray"
        },
        "oneOf": {
          "$ref": "#/$defs/schemaArray"
        },
        "not": {
          "$ref": "#/$defs/flowSchema"
        },
        "if": {
          "$ref": "#/$defs/flowSchema"
        },
        "then": {
          "$ref": "#/$defs/flowSchema"
        },
        "else": {
          "$ref": "#/$defs/flowSchema"
        },
        "properties": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/flowSchema"
          }
        },
        "required": {
          "$ref": "#/$defs/stringArray"
        },
        "additionalProperties": {
          "$ref": "#/$defs/flowSchema"
        },
        "minProperties": {
          "type": "integer",
          "minimum": 0
        },
        "maxProperties": {
          "type": "integer",
          "minimum": 0
        },
        "dependentRequired": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/stringArray"
          }
        },
        "dependentSchemas": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/flowSchema"
          }
        },
        "prefixItems": {
          "$ref": "#/$defs/schemaArray"
        },
        "items": {
          "$ref": "#/$defs/flowSchema"
        },
        "contains": {
          "$ref": "#/$defs/flowSchema"
        },
        "minContains": {
          "type": "integer",
          "minimum": 0
        },
        "maxContains": {
          "type": "integer",
          "minimum": 0
        },
        "minItems": {
          "type": "integer",
          "minimum": 0
        },
        "maxItems": {
          "type": "integer",
          "minimum": 0
        },
        "minLength": {
          "type": "integer",
          "minimum": 0
        },
        "maxLength": {
          "type": "integer",
          "minimum": 0
        },
        "minimum": {
          "type": "number"
        },
        "exclusiveMinimum": {
          "type": "number"
        },
        "maximum": {
          "type": "number"
        },
        "exclusiveMaximum": {
          "type": "number"
        }
      },
      "additionalProperties": false
    }
  }
}