{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://forms.takoform.com/schemas/v1alpha1/form-definition.schema.json",
  "title": "Takoform data-only Form Definition v1alpha1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "apiVersion",
    "kind",
    "definitionVersion",
    "title",
    "status",
    "desiredSchema",
    "observedSchema",
    "lifecycleCapabilities"
  ],
  "properties": {
    "apiVersion": {
      "const": "forms.takoform.com/v1alpha1"
    },
    "kind": {
      "type": "string",
      "pattern": "^[A-Z][A-Za-z0-9]{0,63}$"
    },
    "definitionVersion": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*)(\\.(0|[1-9][0-9]*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*))*))?(\\+([0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*))?$"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160
    },
    "description": {
      "type": "string",
      "maxLength": 4096
    },
    "status": {
      "enum": ["compatibility-candidate", "standard", "deprecated"]
    },
    "desiredSchema": {
      "$ref": "#/$defs/jsonSchema"
    },
    "observedSchema": {
      "$ref": "#/$defs/jsonSchema"
    },
    "outputSchema": {
      "$ref": "#/$defs/jsonSchema"
    },
    "immutableFields": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^(?:/(?:[^~/]|~0|~1)*)+$"
      }
    },
    "lifecycleCapabilities": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "enum": ["create", "read", "update", "delete", "import", "observe", "refresh", "drift"]
      }
    },
    "interfaces": {
      "type": "array",
      "maxItems": 64,
      "uniqueItems": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "version"],
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$",
            "maxLength": 128
          },
          "version": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$"
          },
          "description": {
            "type": "string",
            "maxLength": 1024
          },
          "required": {
            "type": "boolean"
          },
          "resourceUriInput": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9._-]{0,63}$"
          },
          "document": {
            "type": "object"
          },
          "documentSchema": {
            "$ref": "#/$defs/jsonSchema"
          },
          "inputs": {
            "type": "array",
            "maxItems": 64,
            "uniqueItems": true,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": ["name", "source"],
              "properties": {
                "name": {
                  "type": "string",
                  "pattern": "^[A-Za-z][A-Za-z0-9._-]{0,63}$"
                },
                "source": {
                  "type": "string",
                  "maxLength": 128,
                  "anyOf": [
                    { "enum": ["literal", "output", "resource_uri"] },
                    { "pattern": "^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)+$" }
                  ]
                },
                "pointer": {
                  "$ref": "#/$defs/jsonPointer"
                },
                "value": {}
              }
            }
          }
        }
      }
    },
    "conformanceFixtures": {
      "type": "array",
      "maxItems": 32,
      "uniqueItems": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "desiredPath"],
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
          },
          "desiredPath": {
            "$ref": "#/$defs/packagePath"
          },
          "observedPath": {
            "$ref": "#/$defs/packagePath"
          },
          "outputPath": {
            "$ref": "#/$defs/packagePath"
          }
        }
      }
    },
    "negativeConformanceFixtures": {
      "type": "array",
      "maxItems": 32,
      "uniqueItems": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "stage", "inputPath", "expectedFailure"],
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
          },
          "stage": {
            "enum": ["desired", "observed", "output"]
          },
          "inputPath": {
            "$ref": "#/$defs/packagePath"
          },
          "expectedFailure": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9._-]{2,127}$"
          }
        }
      }
    }
  },
  "$defs": {
    "jsonSchema": {
      "type": "object",
      "required": ["$schema", "type"],
      "properties": {
        "$schema": {
          "const": "https://json-schema.org/draft/2020-12/schema"
        },
        "type": {}
      }
    },
    "jsonPointer": {
      "type": "string",
      "maxLength": 512,
      "pattern": "^(?:/(?:[^~/]|~[01])*)*$"
    },
    "packagePath": {
      "type": "string",
      "minLength": 1,
      "maxLength": 240,
      "pattern": "^[A-Za-z0-9._-]+(/[A-Za-z0-9._-]+)*$",
      "not": {
        "pattern": "(^|/)\\.\\.?($|/)"
      }
    }
  }
}
