{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/folio/main/json-schema/folio-agreement-schema.json",
  "title": "Agreement",
  "x-generated": "2026-10-09",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/folio-mod-agreements-openapi.yml#/components/schemas/Agreement",
  "type": "object",
  "required": [
    "id",
    "name",
    "agreementStatus",
    "periods"
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "readOnly": true
    },
    "dateCreated": {
      "type": "string",
      "format": "date-time",
      "readOnly": true
    },
    "lastUpdated": {
      "type": "string",
      "format": "date-time",
      "readOnly": true
    },
    "version": {
      "type": "integer",
      "readOnly": true,
      "description": "GORM optimistic-locking version, incremented on every update."
    },
    "name": {
      "type": "string",
      "maxLength": 255,
      "minLength": 1
    },
    "description": {
      "type": "string"
    },
    "agreementStatus": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "$ref": "#/$defs/Refdata"
        }
      ]
    },
    "isPerpetual": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "$ref": "#/$defs/Refdata"
        }
      ]
    },
    "reasonForClosure": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "$ref": "#/$defs/Refdata"
        }
      ]
    },
    "renewalPriority": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "$ref": "#/$defs/Refdata"
        }
      ]
    },
    "alternateNames": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AlternateName"
      }
    },
    "localReference": {
      "type": "string"
    },
    "vendorReference": {
      "type": "string"
    },
    "agreementContentTypes": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AgreementContentType"
      }
    },
    "periods": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "startDate"
        ],
        "properties": {
          "startDate": {
            "type": "string",
            "format": "date"
          },
          "endDate": {
            "type": "string",
            "format": "date"
          },
          "cancellationDeadline": {
            "type": "string",
            "format": "date"
          },
          "periodStatus": {
            "type": "string"
          },
          "note": {
            "type": "string"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          }
        }
      }
    },
    "startDate": {
      "type": "string",
      "format": "date",
      "readOnly": true
    },
    "endDate": {
      "type": [
        "string",
        "null"
      ],
      "format": "date",
      "readOnly": true,
      "description": "Null if any period on the agreement is open-ended (has no end date)"
    },
    "cancellationDeadline": {
      "type": [
        "string",
        "null"
      ],
      "format": "date",
      "readOnly": true,
      "description": "Null if no period on the agreement has a cancellation deadline set"
    },
    "contacts": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/InternalContact"
      }
    },
    "orgs": {
      "type": "array",
      "description": "Organisations associated with the agreement",
      "items": {
        "$ref": "#/$defs/AgreementOrg"
      }
    },
    "externalLicenseDocs": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/DocumentAttachment"
      }
    },
    "supplementaryDocs": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/DocumentAttachment"
      }
    },
    "linkedLicenses": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/LinkedLicense"
      }
    },
    "usageDataProviders": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/UsageDataProvider"
      }
    },
    "inwardRelationships": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AgreementRelationship"
      }
    },
    "outwardRelationships": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AgreementRelationship"
      }
    },
    "tags": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Tag"
      }
    },
    "customProperties": {
      "type": "object",
      "description": "Custom properties (agreement supplementary properties) — keys are property names, values are arrays of property value instances",
      "additionalProperties": {
        "type": "array",
        "items": {
          "$ref": "#/$defs/CustomPropertyValue"
        }
      }
    }
  },
  "$defs": {
    "AgreementContentType": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid",
          "readOnly": true
        },
        "contentType": {
          "$ref": "#/$defs/Refdata"
        }
      }
    },
    "AgreementOrg": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid",
          "readOnly": true
        },
        "owner": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "format": "uuid"
            }
          },
          "readOnly": true,
          "description": "Agreement that owns the organisation"
        },
        "org": {
          "$ref": "#/$defs/Organisation"
        },
        "primaryOrg": {
          "type": "boolean",
          "description": "Whether this is the primary organisation for the agreement",
          "default": false
        },
        "note": {
          "type": "string",
          "description": "A note about this organisation's relationship to the agreement"
        },
        "roles": {
          "type": "array",
          "description": "The roles this organisation plays in relation to the agreement",
          "items": {
            "type": "object",
            "required": [
              "id",
              "role"
            ],
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid",
                "readOnly": true
              },
              "owner": {
                "$ref": "#/$defs/AgreementOrg",
                "readOnly": true
              },
              "role": {
                "description": "The role (e.g. Content provider)",
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "$ref": "#/$defs/Refdata"
                  }
                ]
              },
              "note": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "AgreementRelationship": {
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "type": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "$ref": "#/$defs/Refdata"
            }
          ]
        },
        "outward": {
          "$ref": "#/$defs/AgreementRelationshipAgreement"
        },
        "inward": {
          "$ref": "#/$defs/AgreementRelationshipAgreement"
        }
      }
    },
    "AgreementRelationshipAgreement": {
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "name": {
          "type": "string"
        },
        "agreementStatus": {
          "$ref": "#/$defs/Refdata"
        },
        "startDate": {
          "type": "string",
          "format": "date"
        },
        "endDate": {
          "type": "string",
          "format": "date"
        }
      }
    },
    "AlternateName": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid",
          "readOnly": true
        },
        "name": {
          "type": "string"
        },
        "owner": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "format": "uuid"
            }
          },
          "readOnly": true,
          "description": "Agreements that owns the alternate name"
        }
      }
    },
    "CustomPropertyDefinition": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "primary": {
          "type": "boolean"
        },
        "defaultInternal": {
          "type": "boolean"
        },
        "retired": {
          "type": "boolean"
        },
        "weight": {
          "type": "integer"
        },
        "type": {
          "type": "string",
          "description": "Java class name indicating the property type (e.g. CustomPropertyInteger, CustomPropertyText, CustomPropertyRefdata)"
        },
        "category": {
          "$ref": "#/$defs/RefdataCategory"
        }
      }
    },
    "CustomPropertyValue": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "readOnly": true
        },
        "internal": {
          "type": "boolean"
        },
        "note": {
          "type": "string"
        },
        "publicNote": {
          "type": "string"
        },
        "value": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "integer"
            },
            {
              "$ref": "#/$defs/Refdata"
            }
          ]
        },
        "type": {
          "$ref": "#/$defs/CustomPropertyDefinition"
        }
      }
    },
    "DocumentAttachment": {
      "type": "object",
      "required": [
        "id",
        "name"
      ],
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "name": {
          "type": "string"
        },
        "dateCreated": {
          "type": "string",
          "format": "date-time"
        },
        "lastUpdated": {
          "type": "string",
          "format": "date-time"
        },
        "location": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "note": {
          "type": "string"
        },
        "atType": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "$ref": "#/$defs/Refdata"
            }
          ]
        },
        "fileUpload": {
          "$ref": "#/$defs/File"
        }
      }
    },
    "File": {
      "type": "object",
      "required": [
        "id",
        "name",
        "size"
      ],
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid",
          "readOnly": true
        },
        "contentType": {
          "type": "string",
          "description": "MIME type of the uploaded file"
        },
        "modified": {
          "type": "string",
          "format": "date-time",
          "readOnly": true
        },
        "name": {
          "type": "string",
          "description": "Original filename of the uploaded file"
        },
        "size": {
          "type": "integer",
          "description": "Size of the uploaded file in bytes"
        }
      }
    },
    "InternalContact": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "owner": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "format": "uuid"
            }
          }
        },
        "role": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "$ref": "#/$defs/Refdata"
            }
          ]
        },
        "user": {
          "type": "string",
          "format": "uuid"
        }
      }
    },
    "LinkedAmendment": {
      "type": "object",
      "properties": {
        "amendmentId": {
          "type": "string",
          "format": "uuid"
        },
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "owner": {
          "type": "string",
          "format": "uuid"
        },
        "status": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "$ref": "#/$defs/Refdata"
            }
          ]
        }
      }
    },
    "LinkedLicense": {
      "type": "object",
      "properties": {
        "amendments": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/LinkedAmendment"
          }
        },
        "id": {
          "type": "string"
        },
        "owner": {
          "type": "string",
          "format": "uuid"
        },
        "remoteId": {
          "type": "string",
          "format": "uuid"
        },
        "remoteId_object": {
          "type": "object"
        },
        "status": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "$ref": "#/$defs/Refdata"
            }
          ]
        }
      }
    },
    "Organisation": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "name": {
          "type": "string"
        },
        "orgsUuid": {
          "type": "string",
          "format": "uuid"
        },
        "orgsUuid_object": {
          "type": "object"
        }
      }
    },
    "Refdata": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "value": {
          "type": "string"
        }
      }
    },
    "RefdataCategory": {
      "type": "object",
      "properties": {
        "desc": {
          "type": "string"
        },
        "id": {
          "type": "string"
        },
        "internal": {
          "type": "boolean"
        },
        "values": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Refdata"
          }
        }
      }
    },
    "Tag": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer"
        },
        "normValue": {
          "type": "string"
        },
        "value": {
          "type": "string"
        }
      }
    },
    "UsageDataProvider": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "owner": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "format": "uuid"
            }
          }
        },
        "remoteId": {
          "type": "string",
          "format": "uuid"
        },
        "remoteId_object": {
          "type": "object"
        }
      }
    }
  }
}