{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.ferretlang.org/registry/artifact/api/v1.json",
  "title": "Ferret Registry API Reference Artifact v1",
  "description": "The statically derived Ferret-facing API for one immutable module version.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "id",
    "version",
    "namespaces"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "id": {
      "$ref": "https://schemas.ferretlang.org/common/identifier.json"
    },
    "version": {
      "$ref": "https://schemas.ferretlang.org/common/semver.json"
    },
    "namespaces": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/namespace"
      }
    }
  },
  "$defs": {
    "ferretIdentifier": {
      "type": "string",
      "pattern": "^[A-Za-z][A-Za-z0-9_]*$"
    },
    "namespace": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "functions"
      ],
      "properties": {
        "name": {
          "oneOf": [
            {
              "const": ""
            },
            {
              "$ref": "https://schemas.ferretlang.org/common/namespace.json"
            }
          ]
        },
        "functions": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/function"
          }
        }
      }
    },
    "function": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "signatures"
      ],
      "properties": {
        "name": {
          "$ref": "#/$defs/ferretIdentifier"
        },
        "signatures": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/signature"
          }
        }
      }
    },
    "signature": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "parameters"
      ],
      "properties": {
        "parameters": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/parameter"
          }
        },
        "variadic": {
          "const": true
        },
        "description": {
          "type": "string",
          "minLength": 1
        },
        "return": {
          "$ref": "#/$defs/return"
        },
        "throws": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/thrownError"
          }
        },
        "deprecated": {
          "type": "string",
          "minLength": 1
        }
      },
      "if": {
        "required": [
          "variadic"
        ]
      },
      "then": {
        "properties": {
          "parameters": {
            "minItems": 1
          }
        }
      },
      "else": {
        "properties": {
          "parameters": {
            "maxItems": 4
          }
        }
      }
    },
    "parameter": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
        },
        "type": {
          "$ref": "#/$defs/type"
        },
        "description": {
          "type": "string",
          "minLength": 1
        }
      },
      "dependentRequired": {
        "type": [
          "description"
        ],
        "description": [
          "type"
        ]
      }
    },
    "return": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "description"
      ],
      "properties": {
        "type": {
          "$ref": "#/$defs/type"
        },
        "description": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "type": {
      "oneOf": [
        {
          "$ref": "#/$defs/namedType"
        },
        {
          "$ref": "#/$defs/unionType"
        },
        {
          "$ref": "#/$defs/listType"
        }
      ]
    },
    "namedType": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "name"
      ],
      "properties": {
        "kind": {
          "const": "named"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "pattern": "\\S",
          "allOf": [
            {
              "pattern": "^[^\\r\\n]+$"
            }
          ]
        }
      }
    },
    "unionType": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "types"
      ],
      "properties": {
        "kind": {
          "const": "union"
        },
        "types": {
          "type": "array",
          "minItems": 2,
          "items": {
            "$ref": "#/$defs/type"
          }
        }
      }
    },
    "listType": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "element"
      ],
      "properties": {
        "kind": {
          "const": "list"
        },
        "element": {
          "$ref": "#/$defs/type"
        }
      }
    },
    "thrownError": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "error",
        "description"
      ],
      "properties": {
        "error": {
          "type": "string",
          "minLength": 1,
          "pattern": "^[^\\r\\n]+$"
        },
        "description": {
          "type": "string",
          "minLength": 1
        }
      }
    }
  }
}
