{
  "openapi": "3.1.0",
  "info": {
    "title": "SCDx local exchange prototype",
    "description": "Experimental SCDx draft profile using synthetic data. Not a production or regulatory filing service.",
    "version": "0.1.0"
  },
  "paths": {
    "/health": {
      "get": {
        "summary": "Health",
        "operationId": "health_health_get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "summary": "Submit",
        "operationId": "submit_v1_messages_post",
        "security": [
          {
            "APIKeyHeader": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExchangeMessage"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SubmissionResponse"
                }
              }
            }
          },
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SubmissionResponse"
                }
              }
            },
            "description": "OK"
          },
          "409": {
            "description": "Conflicting retry or correction"
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List Messages",
        "operationId": "list_messages_v1_messages_get",
        "security": [
          {
            "APIKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "maximum": 100,
              "minimum": 1,
              "default": 50,
              "title": "Limit"
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0,
              "title": "Offset"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MessagePage"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages/{exchange_id}": {
      "get": {
        "summary": "Get Message",
        "operationId": "get_message_v1_messages__exchange_id__get",
        "security": [
          {
            "APIKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "exchange_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Exchange Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MessageRecord"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages/{exchange_id}/receipts": {
      "post": {
        "summary": "Receipt",
        "operationId": "receipt_v1_messages__exchange_id__receipts_post",
        "security": [
          {
            "APIKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "exchange_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Exchange Id"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReceiptRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReceiptResponse"
                }
              }
            }
          },
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReceiptResponse"
                }
              }
            },
            "description": "OK"
          },
          "409": {
            "description": "Receipt already exists with different content"
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "DocumentReference": {
        "properties": {
          "identifier": {
            "$ref": "#/components/schemas/Identifier"
          },
          "document_type": {
            "type": "string",
            "maxLength": 200,
            "minLength": 1,
            "title": "Document Type"
          },
          "status": {
            "type": "string",
            "enum": [
              "issued",
              "replaced",
              "cancelled"
            ],
            "title": "Status"
          },
          "issuer_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
            "title": "Issuer Id"
          },
          "sha256": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              },
              {
                "type": "null"
              }
            ],
            "title": "Sha256"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "identifier",
          "document_type",
          "status",
          "issuer_id"
        ],
        "title": "DocumentReference"
      },
      "ExchangeMessage": {
        "properties": {
          "schema_version": {
            "type": "string",
            "const": "0.1.0",
            "title": "Schema Version"
          },
          "message_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
            "title": "Message Id"
          },
          "message_type": {
            "type": "string",
            "enum": [
              "shipment_event",
              "document_notice",
              "correction"
            ],
            "title": "Message Type"
          },
          "issuer_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
            "title": "Issuer Id"
          },
          "recipient_ids": {
            "items": {
              "type": "string",
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$"
            },
            "type": "array",
            "maxItems": 50,
            "minItems": 1,
            "title": "Recipient Ids"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "title": "Created At"
          },
          "journey": {
            "$ref": "#/components/schemas/Journey"
          },
          "shipment": {
            "$ref": "#/components/schemas/Shipment"
          },
          "event": {
            "$ref": "#/components/schemas/SupplyChainEvent"
          },
          "documents": {
            "items": {
              "$ref": "#/components/schemas/DocumentReference"
            },
            "type": "array",
            "maxItems": 50,
            "title": "Documents"
          },
          "supersedes": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
              },
              {
                "type": "null"
              }
            ],
            "title": "Supersedes"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "schema_version",
          "message_id",
          "message_type",
          "issuer_id",
          "recipient_ids",
          "created_at",
          "journey",
          "shipment",
          "event"
        ],
        "title": "ExchangeMessage"
      },
      "GoodsItem": {
        "properties": {
          "identifier": {
            "$ref": "#/components/schemas/Identifier"
          },
          "description": {
            "type": "string",
            "maxLength": 500,
            "minLength": 1,
            "title": "Description"
          },
          "quantity": {
            "type": "number",
            "exclusiveMinimum": 0.0,
            "title": "Quantity"
          },
          "unit": {
            "type": "string",
            "maxLength": 20,
            "minLength": 1,
            "title": "Unit"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "identifier",
          "description",
          "quantity",
          "unit"
        ],
        "title": "GoodsItem"
      },
      "HTTPValidationError": {
        "properties": {
          "detail": {
            "items": {
              "$ref": "#/components/schemas/ValidationError"
            },
            "type": "array",
            "title": "Detail"
          }
        },
        "type": "object",
        "title": "HTTPValidationError"
      },
      "Identifier": {
        "properties": {
          "scheme": {
            "type": "string",
            "maxLength": 200,
            "minLength": 1,
            "title": "Scheme"
          },
          "value": {
            "type": "string",
            "maxLength": 200,
            "minLength": 1,
            "title": "Value"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "scheme",
          "value"
        ],
        "title": "Identifier"
      },
      "Journey": {
        "properties": {
          "journey_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
            "title": "Journey Id"
          },
          "trade_flow": {
            "type": "string",
            "enum": [
              "import",
              "export",
              "interprovincial"
            ],
            "title": "Trade Flow"
          },
          "origin": {
            "$ref": "#/components/schemas/Location"
          },
          "destination": {
            "$ref": "#/components/schemas/Location"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "journey_id",
          "trade_flow",
          "origin",
          "destination"
        ],
        "title": "Journey"
      },
      "Location": {
        "properties": {
          "identifier": {
            "$ref": "#/components/schemas/Identifier"
          },
          "name": {
            "type": "string",
            "maxLength": 200,
            "minLength": 1,
            "title": "Name"
          },
          "node_type": {
            "type": "string",
            "enum": [
              "port",
              "terminal",
              "warehouse",
              "supplier",
              "receiver",
              "facility"
            ],
            "title": "Node Type"
          },
          "country": {
            "type": "string",
            "pattern": "^[A-Z]{2}$",
            "title": "Country"
          },
          "subdivision": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 16,
                "minLength": 1
              },
              {
                "type": "null"
              }
            ],
            "title": "Subdivision"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "identifier",
          "name",
          "node_type",
          "country"
        ],
        "title": "Location"
      },
      "MessagePage": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/MessageRecord"
            },
            "type": "array",
            "title": "Items"
          },
          "limit": {
            "type": "integer",
            "title": "Limit"
          },
          "offset": {
            "type": "integer",
            "title": "Offset"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "items",
          "limit",
          "offset"
        ],
        "title": "MessagePage"
      },
      "MessageRecord": {
        "properties": {
          "exchange_id": {
            "type": "string",
            "title": "Exchange Id"
          },
          "received_at": {
            "type": "string",
            "title": "Received At"
          },
          "superseded_by": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Superseded By"
          },
          "message": {
            "$ref": "#/components/schemas/ExchangeMessage"
          },
          "receipts": {
            "items": {
              "$ref": "#/components/schemas/Receipt"
            },
            "type": "array",
            "title": "Receipts"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "exchange_id",
          "received_at",
          "superseded_by",
          "message",
          "receipts"
        ],
        "title": "MessageRecord"
      },
      "Receipt": {
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "accepted",
              "rejected"
            ],
            "title": "Status"
          },
          "detail": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 1000
              },
              {
                "type": "null"
              }
            ],
            "title": "Detail"
          },
          "organization_id": {
            "type": "string",
            "title": "Organization Id"
          },
          "recorded_at": {
            "type": "string",
            "title": "Recorded At"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "status",
          "organization_id",
          "recorded_at"
        ],
        "title": "Receipt"
      },
      "ReceiptRequest": {
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "accepted",
              "rejected"
            ],
            "title": "Status"
          },
          "detail": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 1000
              },
              {
                "type": "null"
              }
            ],
            "title": "Detail"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "status"
        ],
        "title": "ReceiptRequest"
      },
      "ReceiptResponse": {
        "properties": {
          "receipt": {
            "$ref": "#/components/schemas/Receipt"
          },
          "duplicate": {
            "type": "boolean",
            "title": "Duplicate"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "receipt",
          "duplicate"
        ],
        "title": "ReceiptResponse"
      },
      "Shipment": {
        "properties": {
          "identifier": {
            "$ref": "#/components/schemas/Identifier"
          },
          "goods": {
            "items": {
              "$ref": "#/components/schemas/GoodsItem"
            },
            "type": "array",
            "maxItems": 100,
            "minItems": 1,
            "title": "Goods"
          },
          "transport_legs": {
            "items": {
              "$ref": "#/components/schemas/TransportLeg"
            },
            "type": "array",
            "maxItems": 30,
            "minItems": 1,
            "title": "Transport Legs"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "identifier",
          "goods",
          "transport_legs"
        ],
        "title": "Shipment"
      },
      "SubmissionResponse": {
        "properties": {
          "record": {
            "$ref": "#/components/schemas/MessageRecord"
          },
          "duplicate": {
            "type": "boolean",
            "title": "Duplicate"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "record",
          "duplicate"
        ],
        "title": "SubmissionResponse"
      },
      "SupplyChainEvent": {
        "properties": {
          "event_type": {
            "type": "string",
            "enum": [
              "planned",
              "departed",
              "arrived",
              "transferred",
              "stored",
              "released",
              "delivered",
              "document_issued",
              "corrected"
            ],
            "title": "Event Type"
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time",
            "title": "Occurred At"
          },
          "location": {
            "$ref": "#/components/schemas/Location"
          },
          "leg_id": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$"
              },
              {
                "type": "null"
              }
            ],
            "title": "Leg Id"
          },
          "authority": {
            "type": "string",
            "maxLength": 200,
            "minLength": 1,
            "title": "Authority"
          },
          "release_scope": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "customs",
                  "carrier",
                  "terminal",
                  "collection"
                ]
              },
              {
                "type": "null"
              }
            ],
            "title": "Release Scope"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "event_type",
          "occurred_at",
          "location",
          "authority"
        ],
        "title": "SupplyChainEvent"
      },
      "TransportLeg": {
        "properties": {
          "leg_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
            "title": "Leg Id"
          },
          "mode": {
            "type": "string",
            "enum": [
              "ship",
              "rail",
              "truck"
            ],
            "title": "Mode"
          },
          "operator_id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$",
            "title": "Operator Id"
          },
          "origin": {
            "$ref": "#/components/schemas/Location"
          },
          "destination": {
            "$ref": "#/components/schemas/Location"
          }
        },
        "additionalProperties": false,
        "type": "object",
        "required": [
          "leg_id",
          "mode",
          "operator_id",
          "origin",
          "destination"
        ],
        "title": "TransportLeg"
      },
      "ValidationError": {
        "properties": {
          "loc": {
            "items": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "integer"
                }
              ]
            },
            "type": "array",
            "title": "Location"
          },
          "msg": {
            "type": "string",
            "title": "Message"
          },
          "type": {
            "type": "string",
            "title": "Error Type"
          },
          "input": {
            "title": "Input"
          },
          "ctx": {
            "type": "object",
            "title": "Context"
          }
        },
        "type": "object",
        "required": [
          "loc",
          "msg",
          "type"
        ],
        "title": "ValidationError"
      }
    },
    "securitySchemes": {
      "APIKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    }
  }
}
