{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/digitraffic-fi/json-schema/digitraffic-fi-composition-schema.json",
  "title": "Composition",
  "description": "Describes train's locomotives and wagons",
  "x-generated": "2026-11-11",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/digitraffic-fi-rail-api-openapi.yml#/components/schemas/Composition",
  "required": [
    "departureDate",
    "trainCategory",
    "trainNumber",
    "trainType"
  ],
  "type": "object",
  "properties": {
    "trainNumber": {
      "type": "integer",
      "description": "Identifies the train inside a single departure date",
      "format": "int64"
    },
    "departureDate": {
      "type": "string",
      "description": "Date of the train's first departure",
      "format": "date"
    },
    "operatorUICCode": {
      "type": "integer",
      "description": "Official UIC code of the operator",
      "format": "int32"
    },
    "operatorShortCode": {
      "type": "string",
      "description": "Short code of the operator"
    },
    "trainCategory": {
      "type": "string"
    },
    "trainType": {
      "type": "string"
    },
    "version": {
      "type": "integer",
      "description": "When was this data last modified",
      "format": "int64"
    },
    "journeySections": {
      "uniqueItems": true,
      "type": "array",
      "items": {
        "$ref": "#/$defs/JourneySection"
      }
    }
  },
  "$defs": {
    "CompositionTimeTableRow": {
      "title": "CompositionTimeTableRow",
      "type": "object",
      "properties": {
        "stationShortCode": {
          "type": "string"
        },
        "stationUICCode": {
          "type": "integer",
          "format": "int32"
        },
        "countryCode": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": [
            "ARRIVAL",
            "DEPARTURE"
          ]
        },
        "scheduledTime": {
          "type": "string",
          "format": "date-time"
        }
      },
      "description": "Describes a point in a trains schedule where its composition changes"
    },
    "JourneySection": {
      "title": "JourneySection",
      "type": "object",
      "properties": {
        "beginTimeTableRow": {
          "$ref": "#/$defs/CompositionTimeTableRow"
        },
        "endTimeTableRow": {
          "$ref": "#/$defs/CompositionTimeTableRow"
        },
        "locomotives": {
          "uniqueItems": true,
          "type": "array",
          "description": "List of locomotives used on this leg",
          "items": {
            "$ref": "#/$defs/Locomotive"
          }
        },
        "wagons": {
          "uniqueItems": true,
          "type": "array",
          "description": "List of wagons used on this leg",
          "items": {
            "$ref": "#/$defs/Wagon"
          }
        },
        "totalLength": {
          "type": "integer",
          "description": "Total length of the train with an accuracy of 1 m",
          "format": "int32"
        },
        "maximumSpeed": {
          "type": "integer",
          "description": "Maximum with an accuracy of 1 km/h",
          "format": "int32"
        }
      },
      "description": "Describes a leg where train's composition is in effect"
    },
    "Locomotive": {
      "title": "Locomotive",
      "type": "object",
      "properties": {
        "location": {
          "type": "integer",
          "description": "Location of the locomotive in the train. 1=start of the train",
          "format": "int32"
        },
        "locomotiveType": {
          "type": "string"
        },
        "powerType": {
          "type": "string"
        },
        "vehicleNumber": {
          "type": "string"
        }
      },
      "description": "List of locomotives used on this leg"
    },
    "Wagon": {
      "title": "Wagon",
      "type": "object",
      "properties": {
        "wagonType": {
          "type": "string"
        },
        "location": {
          "type": "integer",
          "format": "int32"
        },
        "salesNumber": {
          "type": "integer",
          "description": "Wagon number in customer's ticket",
          "format": "int32"
        },
        "length": {
          "type": "integer",
          "description": "Wagon length in centimeters",
          "format": "int32"
        },
        "playground": {
          "type": "boolean"
        },
        "pet": {
          "type": "boolean"
        },
        "catering": {
          "type": "boolean"
        },
        "video": {
          "type": "boolean"
        },
        "luggage": {
          "type": "boolean"
        },
        "smoking": {
          "type": "boolean"
        },
        "disabled": {
          "type": "boolean"
        },
        "vehicleNumber": {
          "type": "string"
        }
      },
      "description": "List of wagons used on this leg"
    }
  }
}