{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://forms.takoform.com/schemas/v1alpha3/form-definition.schema.json",
  "title": "Takoform data-only Form Definition v1alpha3",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "apiVersion",
    "kind",
    "definitionVersion",
    "title",
    "role",
    "desiredSchema",
    "lifecycleCapabilities"
  ],
  "properties": {
    "apiVersion": {
      "type": "string",
      "maxLength": 320,
      "pattern": "^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+/v[0-9]+(?:(?:alpha|beta)[0-9]+)?$",
      "not": {
        "enum": ["forms.takoform.com/v1alpha1", "forms.takoform.com/v1alpha2"]
      }
    },
    "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
    },
    "role": {
      "enum": ["identity", "revision", "deployment", "attachment", "policy"],
      "description": "Closed resource role. Revisions are immutable snapshots and never declare the update capability; attachments and policies reference a parent resource; deleting an attachment or policy never deletes the parent."
    },
    "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"]
      }
    },
    "providedInterfaces": {
      "type": "array",
      "maxItems": 64,
      "uniqueItems": true,
      "items": {
        "$ref": "https://forms.takoform.com/schemas/interfaces/v1alpha1/interface-ref.schema.json"
      },
      "description": "Exact Interface contracts every resource of this Form provides."
    },
    "acceptedBindings": {
      "type": "array",
      "maxItems": 64,
      "uniqueItems": true,
      "items": {
        "$ref": "https://forms.takoform.com/schemas/bindings/v1alpha1/binding-ref.schema.json"
      },
      "description": "Exact Binding contracts resources of this Form may hold as a source. Only revision-role Forms hold capability bindings."
    },
    "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}$"
          }
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "role": {
            "const": "revision"
          }
        },
        "required": ["role"]
      },
      "then": {
        "properties": {
          "lifecycleCapabilities": {
            "items": {
              "enum": ["create", "read", "delete", "import", "observe"]
            }
          }
        }
      }
    }
  ],
  "$defs": {
    "jsonSchema": {
      "type": "object",
      "required": ["$schema", "type"],
      "properties": {
        "$schema": {
          "const": "https://json-schema.org/draft/2020-12/schema"
        },
        "type": {}
      }
    },
    "packagePath": {
      "type": "string",
      "minLength": 1,
      "maxLength": 240,
      "pattern": "^[A-Za-z0-9._-]+(/[A-Za-z0-9._-]+)*$",
      "not": {
        "pattern": "(^|/)\\.\\.?($|/)"
      }
    }
  }
}
