openapi: 3.0.3 info: title: Linehaul Transportation API version: 0.1.0 contact: name: linehaul-transportation maintainers url: https://github.com/IQVO/linehaul-transportation description: >- REST contract of the linehaul-transportation bounded context of the retail network, derived from retail-network-docs apis/linehaul-transportation/openapi.yaml and model/model.yaml (contexts[linehaul-transportation].rest), adjusted by the Model Gap Register decisions G3, G9, G14, G15, G28 and G29 and by the cross-context decisions E3, E13, E14 and E16 (ADR 0002). The service runs the middle mile: it turns lane schedules and the declared cutoffs of vendor nodes into scheduled departures, keeps each departure's remaining capacity, builds loads of packages onto departures and reports when loads depart and arrive. The planner calls the lane-schedule routes, the departure cancellation and capacity routes; sort-centre and station operators call the load routes; any context may call the departure reads. Domain events are published on Kafka (apis/asyncapi.yaml), never over REST. No authentication, consistent with the fleet. Errors are RFC 9457 problem details; the shared problem types are not-found (404), illegal-transition (409), concurrent-update (409) and validation-failed (422), plus one type per model Err name. Every POST takes a required Idempotency-Key; PUT is idempotent by method. servers: - url: http://localhost:8080 tags: - name: Lane schedules description: Weekly templates that generate a lane's departures (aggregate LaneSchedule). - name: Departures description: Scheduled trips on lanes with cutoff and package capacity (aggregate Departure). - name: Loads description: Packages consolidated onto one departure at its origin node (aggregate Load). paths: /lane-schedules: post: tags: [Lane schedules] operationId: defineLaneSchedule summary: Define the weekly schedule of a lane (DefineLaneSchedule) description: >- Creates the ACTIVE weekly template of one lane, or replaces the slots of an ACTIVE template (201 on creation, 200 on replacement; a redefinition takes effect from the next horizon roll, departures that were already generated stay). The lane must be known (LaneView). Slots must not overlap on the same weekday (overlapping-slots). A RETIRED schedule cannot be redefined (illegal-transition). Raises no event. Departures are generated by GenerateDepartures (policy HorizonRoll). parameters: - $ref: '#/components/parameters/IdempotencyKey' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/DefineLaneScheduleRequest' responses: '200': description: Slots of an ACTIVE schedule replaced. headers: Idempotency-Replayed: $ref: '#/components/headers/IdempotencyReplayed' content: application/json: schema: $ref: '#/components/schemas/LaneSchedule' '201': description: Schedule defined. headers: Idempotency-Replayed: $ref: '#/components/headers/IdempotencyReplayed' content: application/json: schema: $ref: '#/components/schemas/LaneSchedule' '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '413': $ref: '#/components/responses/TooLarge' '422': $ref: '#/components/responses/Unprocessable' '500': $ref: '#/components/responses/InternalError' /lane-schedules/{laneId}/retirements: post: tags: [Lane schedules] operationId: retireLaneSchedule summary: Retire the schedule of a lane (RetireLaneSchedule) description: >- Moves the schedule from ACTIVE to RETIRED; GenerateDepartures skips it from now on and the departures already generated stay. Retiring a RETIRED schedule returns it unchanged. Raises no event. parameters: - $ref: '#/components/parameters/LaneId' - $ref: '#/components/parameters/IdempotencyKey' responses: '200': description: Schedule retired (or already retired). headers: Idempotency-Replayed: $ref: '#/components/headers/IdempotencyReplayed' content: application/json: schema: $ref: '#/components/schemas/LaneSchedule' '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '413': $ref: '#/components/responses/TooLarge' '422': $ref: '#/components/responses/Unprocessable' '500': $ref: '#/components/responses/InternalError' /departures: get: tags: [Departures] operationId: listDepartures summary: List departures by origin, destination and time window (ListDepartures) description: >- Open Host Service read for any context. Filters are ANDed; from and to bound cutoffAt (from inclusive, to exclusive). Ordered by cutoffAt then departureId, keyset-paged: limit (1-500, default 100) and the opaque cursor from nextCursor; filters are repeated on every page request. Any other query parameter is 400 unknown-query-parameter. parameters: - name: origin in: query required: false description: Origin node id. schema: type: string - name: destination in: query required: false description: Destination node id. schema: type: string - name: from in: query required: false description: Earliest cutoffAt, inclusive. schema: type: string format: date-time - name: to in: query required: false description: Latest cutoffAt, exclusive. schema: type: string format: date-time - $ref: '#/components/parameters/Limit' - $ref: '#/components/parameters/Cursor' responses: '200': description: Matching departures. content: application/json: schema: $ref: '#/components/schemas/DepartureList' '400': $ref: '#/components/responses/BadRequest' '422': $ref: '#/components/responses/Unprocessable' '500': $ref: '#/components/responses/InternalError' /departures/{departureId}: get: tags: [Departures] operationId: getDeparture summary: Get one departure description: Returns the departure with its capacity, booked and remaining packages and its state. parameters: - $ref: '#/components/parameters/DepartureId' responses: '200': description: The departure. content: application/json: schema: $ref: '#/components/schemas/Departure' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' /departures/{departureId}/cancellations: post: tags: [Departures] operationId: cancelDeparture summary: Cancel a scheduled departure (CancelDeparture) description: >- Moves a SCHEDULED departure to CANCELLED and publishes DepartureCancelled, which delivery-promise and order-sourcing use to re-promise. Every assignment booked on the departure is rebooked onto the next departure from the same origin (BookingMoved) or reported as BookingFailed when none fits. Cancel before cutoffAt wherever possible. Cancelling a CANCELLED departure returns it unchanged. parameters: - $ref: '#/components/parameters/DepartureId' - $ref: '#/components/parameters/IdempotencyKey' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/CancelDepartureRequest' responses: '200': description: Departure cancelled (or already cancelled). headers: Idempotency-Replayed: $ref: '#/components/headers/IdempotencyReplayed' content: application/json: schema: $ref: '#/components/schemas/Departure' '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '413': $ref: '#/components/responses/TooLarge' '422': $ref: '#/components/responses/Unprocessable' '500': $ref: '#/components/responses/InternalError' /departures/{departureId}/capacity: put: tags: [Departures] operationId: changeDepartureCapacity summary: Change the package capacity of a scheduled departure (ChangeDepartureCapacity) description: >- Planner command added by gap G28. Allowed on a SCHEDULED departure; the new capacity may not be below the packages already booked (departure-full). Publishes DepartureCapacityChanged. A capacity equal to the current one changes nothing and publishes nothing. A load that is already open keeps the capacity snapshot it took at OpenLoad. parameters: - $ref: '#/components/parameters/DepartureId' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/ChangeDepartureCapacityRequest' responses: '200': description: Capacity changed. content: application/json: schema: $ref: '#/components/schemas/Departure' '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '422': $ref: '#/components/responses/Unprocessable' '500': $ref: '#/components/responses/InternalError' /loads: post: tags: [Loads] operationId: openLoad summary: Open a load on a departure (OpenLoad) description: >- Opens the load of a SCHEDULED departure, copying the origin, destination, departure kind, node types and the capacity of the departure into the load. A departure has at most one load (load-already-exists). Raises no event. parameters: - $ref: '#/components/parameters/IdempotencyKey' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/OpenLoadRequest' responses: '201': description: Load opened. headers: Idempotency-Replayed: $ref: '#/components/headers/IdempotencyReplayed' content: application/json: schema: $ref: '#/components/schemas/Load' '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '413': $ref: '#/components/responses/TooLarge' '422': $ref: '#/components/responses/Unprocessable' '500': $ref: '#/components/responses/InternalError' /loads/{loadId}/packages: post: tags: [Loads] operationId: addPackageToLoad summary: Add a package to an open load (AddPackage) description: >- Refused with 409 package-already-loaded (ErrPackageAlreadyLoaded) if the tracking number is on another OPEN or CLOSED load, and with 409 load-over-capacity (ErrLoadOverCapacity) if the load would exceed its capacity snapshot. On a LINEHAUL or AIR departure the package is also booked on the departure (gap G15): 409 departure-full or departure-closed when it cannot be. On a PICKUP departure the booking was made at FulfillmentLocked and booked does not change. Adding a tracking number that is already on this load changes nothing. parameters: - $ref: '#/components/parameters/LoadId' - $ref: '#/components/parameters/IdempotencyKey' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/AddPackageRequest' responses: '200': description: Package added (or already on this load). headers: Idempotency-Replayed: $ref: '#/components/headers/IdempotencyReplayed' content: application/json: schema: $ref: '#/components/schemas/Load' '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '413': $ref: '#/components/responses/TooLarge' '422': $ref: '#/components/responses/Unprocessable' '500': $ref: '#/components/responses/InternalError' /loads/{loadId}/closures: post: tags: [Loads] operationId: closeLoad summary: Close an open load (CloseLoad) description: >- OPEN to CLOSED; closes the departure of the load (CloseDeparture) and publishes LoadClosed on the analytics stream. Closing a CLOSED load returns it unchanged. parameters: - $ref: '#/components/parameters/LoadId' - $ref: '#/components/parameters/IdempotencyKey' responses: '200': description: Load closed (or already closed). headers: Idempotency-Replayed: $ref: '#/components/headers/IdempotencyReplayed' content: application/json: schema: $ref: '#/components/schemas/Load' '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '413': $ref: '#/components/responses/TooLarge' '422': $ref: '#/components/responses/Unprocessable' '500': $ref: '#/components/responses/InternalError' /loads/{loadId}/dispatches: post: tags: [Loads] operationId: dispatchLoad summary: Dispatch a closed load (DispatchLoad) description: >- CLOSED to DEPARTED; records the departure of the trip (RecordDeparture) and publishes LoadDeparted (with departureKind and nodeType) and DepartureDeparted. Dispatching a DEPARTED load returns it unchanged. parameters: - $ref: '#/components/parameters/LoadId' - $ref: '#/components/parameters/IdempotencyKey' responses: '200': description: Load dispatched (or already dispatched). headers: Idempotency-Replayed: $ref: '#/components/headers/IdempotencyReplayed' content: application/json: schema: $ref: '#/components/schemas/Load' '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '413': $ref: '#/components/responses/TooLarge' '422': $ref: '#/components/responses/Unprocessable' '500': $ref: '#/components/responses/InternalError' /loads/{loadId}/receipts: post: tags: [Loads] operationId: receiveLoad summary: Receive a load at its destination node (ReceiveLoad) description: >- DEPARTED to ARRIVED; records the arrival of the trip (RecordArrival) and publishes LoadArrived (with departureKind and nodeType), which last-mile-delivery uses to induct the packages at a delivery station, and DepartureArrived. Receiving an ARRIVED load returns it unchanged. parameters: - $ref: '#/components/parameters/LoadId' - $ref: '#/components/parameters/IdempotencyKey' responses: '200': description: Load received (or already received). headers: Idempotency-Replayed: $ref: '#/components/headers/IdempotencyReplayed' content: application/json: schema: $ref: '#/components/schemas/Load' '400': $ref: '#/components/responses/BadRequest' '404': $ref: '#/components/responses/NotFound' '409': $ref: '#/components/responses/Conflict' '413': $ref: '#/components/responses/TooLarge' '422': $ref: '#/components/responses/Unprocessable' '500': $ref: '#/components/responses/InternalError' components: parameters: IdempotencyKey: name: Idempotency-Key in: header required: true description: >- Client-generated key (1 to 128 printable ASCII characters), one per logical submit. A repeat of the same request (method, path, body) with the same key within 24 hours returns the first response (status and body, header Idempotency-Replayed: true) when that response is final for the request: a 2xx, or a refusal that is a function of the request alone. A refusal that depends on state another request can change is not stored and the key is released, so a retry under the same key runs again (with another body it is a new request). These problem types are not stored and release the key: concurrent-update, departure-closed, departure-full, illegal-transition, lane-closed, not-found, package-already-loaded. A server failure (5xx) is never stored. While a key holds a stored answer, the same key with another request is 409 idempotency-key-reused. schema: type: string minLength: 1 maxLength: 128 Limit: name: limit in: query required: false description: Maximum number of items per page. schema: type: integer minimum: 1 maximum: 500 default: 100 Cursor: name: cursor in: query required: false description: Opaque cursor taken from nextCursor of the previous page. schema: type: string LaneId: name: laneId in: path required: true description: Lane id (owned by node-topology). schema: type: string DepartureId: name: departureId in: path required: true description: Departure id. schema: type: string LoadId: name: loadId in: path required: true description: Load id. schema: type: string headers: IdempotencyReplayed: description: Present, with the value true, only on a response replayed from a stored first answer (a 2xx or a refusal that is final for the request; a 5xx and a refusal that depends on state another request can change are never stored). schema: type: string enum: ['true'] responses: BadRequest: description: >- Malformed request. Types: malformed-request (bad JSON, unknown field, NUL character), idempotency-key-required, idempotency-key-invalid, invalid-limit, invalid-cursor and unknown-query-parameter. content: application/problem+json: schema: $ref: '#/components/schemas/Problem' TooLarge: description: Request body above 64 KiB (problem type request-body-too-large). content: application/problem+json: schema: $ref: '#/components/schemas/Problem' InternalError: description: >- Unexpected failure (problem type internal-error); the detail never carries the internal message. A 5xx is never stored by the Idempotency-Key middleware, so the same key can retry. content: application/problem+json: schema: $ref: '#/components/schemas/Problem' NotFound: description: >- Unknown id (problem type not-found), or a NUL character in the request path (problem type resource-not-found). content: application/problem+json: schema: $ref: '#/components/schemas/Problem' Conflict: description: >- State or capacity conflict, or Idempotency-Key reuse. Types: idempotency-key-reused (the key was already used with a different request), departure-full (ErrDepartureFull), departure-closed (ErrDepartureClosed), lane-closed (ErrLaneClosed), package-already-loaded (ErrPackageAlreadyLoaded), load-over-capacity (ErrLoadOverCapacity), load-already-exists (ErrLoadAlreadyExists), illegal-transition and concurrent-update. content: application/problem+json: schema: $ref: '#/components/schemas/Problem' Unprocessable: description: >- Validation failure. Types: overlapping-slots (ErrOverlappingSlots), invalid-departure-times (ErrInvalidDepartureTimes) and validation-failed. An empty request body is decoded as all-zero values and fails here (validation-failed), not as a 400. content: application/problem+json: schema: $ref: '#/components/schemas/Problem' schemas: Problem: type: object description: RFC 9457 problem details. required: [type, title, status, detail, instance] properties: type: type: string format: uri example: https://retailnetwork.example/problems/departure-full title: type: string example: Departure full status: type: integer example: 409 detail: type: string example: booked equals capacity on this departure instance: type: string description: Escaped request path. DepartureKind: type: string enum: [PICKUP, LINEHAUL, AIR] DepartureState: type: string enum: [SCHEDULED, CLOSED, DEPARTED, ARRIVED, CANCELLED] Departure: type: object required: [departureId, laneId, kind, originNodeId, destinationNodeId, cutoffAt, departsAt, arrivesAt, capacityPackages, bookedPackages, remainingPackages, state] properties: departureId: type: string laneId: type: string kind: $ref: '#/components/schemas/DepartureKind' originNodeId: type: string destinationNodeId: type: string cutoffAt: type: string format: date-time description: No booking after this instant (ErrDepartureClosed). departsAt: type: string format: date-time arrivesAt: type: string format: date-time capacityPackages: type: integer minimum: 0 bookedPackages: type: integer minimum: 0 description: Never above capacityPackages (ErrDepartureFull). remainingPackages: type: integer minimum: 0 state: $ref: '#/components/schemas/DepartureState' cancelReason: type: string description: Present when the state is CANCELLED. cancelledAt: type: string format: date-time description: Present when the state is CANCELLED. departedAt: type: string format: date-time description: Present once the state reached DEPARTED. arrivedAt: type: string format: date-time description: Present once the state reached ARRIVED. DepartureList: type: object required: [items] properties: items: type: array items: $ref: '#/components/schemas/Departure' nextCursor: type: string description: Opaque cursor of the next page; absent on the last page. CancelDepartureRequest: type: object required: [reason] properties: reason: type: string minLength: 1 maxLength: 200 description: Trimmed, without control characters (validation-failed otherwise). ChangeDepartureCapacityRequest: type: object required: [capacityPackages] properties: capacityPackages: type: integer minimum: 0 maximum: 2147483647 LaneScheduleSlot: type: object description: >- One weekly slot (gap G29). cutoffLocalTime and departsLocalTime are wall-clock times in the time zone of the lane's origin node, arrivesLocalTime in the time zone of its destination node; the arrival is the first instant after the departure with that wall-clock time. required: [dayOfWeek, cutoffLocalTime, departsLocalTime, arrivesLocalTime, capacityPackages] properties: dayOfWeek: type: string enum: [MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY] cutoffLocalTime: type: string pattern: '^([01][0-9]|2[0-3]):[0-5][0-9]$' example: '18:00' departsLocalTime: type: string pattern: '^([01][0-9]|2[0-3]):[0-5][0-9]$' description: Not before cutoffLocalTime (invalid-departure-times). example: '18:30' arrivesLocalTime: type: string pattern: '^([01][0-9]|2[0-3]):[0-5][0-9]$' example: '22:45' capacityPackages: type: integer minimum: 1 maximum: 2147483647 DefineLaneScheduleRequest: type: object required: [laneId, slots] properties: laneId: type: string slots: type: array minItems: 1 maxItems: 100 description: Slots must not overlap on the same weekday (ErrOverlappingSlots). items: $ref: '#/components/schemas/LaneScheduleSlot' LaneSchedule: type: object required: [laneId, state, slots] properties: laneId: type: string state: type: string enum: [ACTIVE, RETIRED] slots: type: array items: $ref: '#/components/schemas/LaneScheduleSlot' OpenLoadRequest: type: object required: [departureId] properties: departureId: type: string AddPackageRequest: type: object required: [trackingNumber] properties: trackingNumber: type: string minLength: 1 maxLength: 64 description: Trimmed, without control characters (validation-failed otherwise). Load: type: object required: [loadId, departureId, departureKind, originNodeId, destinationNodeId, capacityPackages, packageCount, trackingNumbers, state] properties: loadId: type: string departureId: type: string departureKind: $ref: '#/components/schemas/DepartureKind' originNodeId: type: string destinationNodeId: type: string capacityPackages: type: integer minimum: 0 description: Snapshot of the departure capacity at OpenLoad (ErrLoadOverCapacity). packageCount: type: integer minimum: 0 trackingNumbers: type: array items: type: string state: type: string enum: [OPEN, CLOSED, DEPARTED, ARRIVED] departedAt: type: string format: date-time description: Present once the load departed. arrivedAt: type: string format: date-time description: Present once the load arrived.