{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/apisign-io/json-schema/apisign-io-create-contract-request-schema.json",
  "title": "CreateContractRequest",
  "x-generated": "2026-11-01",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/apisign-io-openapi.yml#/components/schemas/CreateContractRequest",
  "type": "object",
  "required": [
    "name",
    "signers"
  ],
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 255
    },
    "template_id": {
      "type": "string",
      "description": "Active template ID (cuid). Omit for a blank contract."
    },
    "content": {
      "type": "string",
      "description": "Markdown. Required for blank contracts; rejected with template_id."
    },
    "variables": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      },
      "description": "Values substituted into the template. Required for every creator-completed template field. Rejected for blank contracts."
    },
    "fields": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/FieldDefinition"
      },
      "description": "Required for blank contracts; rejected with template_id."
    },
    "signers": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/CreateSignerInput"
      }
    },
    "expires_in_days": {
      "type": "integer",
      "minimum": 1,
      "maximum": 365,
      "default": 30
    },
    "test_mode": {
      "type": "boolean",
      "default": false,
      "description": "Fixed at creation"
    },
    "metadata": {
      "type": "object"
    }
  },
  "$defs": {
    "CreateSignerInput": {
      "type": "object",
      "required": [
        "email",
        "name",
        "signing_order"
      ],
      "properties": {
        "email": {
          "type": "string",
          "format": "email"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        },
        "signing_order": {
          "type": "integer",
          "minimum": 1,
          "description": "Unique per contract. Display order only; does not enforce a signing sequence."
        },
        "company": {
          "type": "string",
          "maxLength": 255
        },
        "mobile": {
          "type": "string",
          "description": "Stored only; nothing is sent to it"
        },
        "signerFields": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Variable names this signer fills in. Required on every signer when there is more than one signer; each needs a signature field no other signer has."
        }
      }
    },
    "FieldDefinition": {
      "type": "object",
      "required": [
        "name",
        "type",
        "completedBy"
      ],
      "properties": {
        "name": {
          "type": "string",
          "description": "Variable name without braces"
        },
        "type": {
          "type": "string",
          "description": "signature, initials, signer_name, timestamp, text, email, phone or date"
        },
        "completedBy": {
          "type": "string",
          "enum": [
            "signer",
            "creator"
          ]
        },
        "label": {
          "type": "string",
          "description": "Prompt shown for a text field"
        }
      }
    }
  }
}