openapi: 3.1.0
info:
  title: Interex Messaging API
  version: 1.0.1
tags:
  - name: Messages
paths:
  /v1/messages:
    get:
      operationId: getMessages
      summary: Retrieve messages
      parameters:
        - $ref: '#/components/parameters/iov42.Headers.RequestHeaderBase'
        - $ref: '#/components/parameters/MessageQuery.lastId'
        - $ref: '#/components/parameters/MessageQuery.count'
        - $ref: '#/components/parameters/MessageQuery.messageType'
        - $ref: '#/components/parameters/MessageQuery.schemaVersion'
        - $ref: '#/components/parameters/MessageQuery.channel'
        - $ref: '#/components/parameters/MessageQuery.entity'
        - $ref: '#/components/parameters/MessageQuery.sent'
        - $ref: '#/components/parameters/MessageQuery.fromTimestamp'
        - $ref: '#/components/parameters/MessageQuery.toTimestamp'
      responses:
        '200':
          description: The request has succeeded.
          headers:
            x-correlation-id:
              required: true
              schema:
                type: string
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Message'
        '401':
          description: Access is unauthorized.
        '403':
          description: Access is forbidden.
        '429':
          description: Too Many Requests
          headers:
            retry-after:
              required: true
              schema:
                type: string
            x-correlation-id:
              required: true
              schema:
                type: string
        '500':
          description: InternalServerError
          headers:
            x-correlation-id:
              required: true
              schema:
                type: string
      tags:
        - Messages
    post:
      operationId: sendMessage
      summary: Send Message
      parameters:
        - $ref: '#/components/parameters/iov42.Headers.RequestHeaderBase'
      responses:
        '201':
          description: >-
            The request has succeeded and a new resource has been created as a
            result.
          headers:
            x-correlation-id:
              required: true
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
        '401':
          description: Access is unauthorized.
        '403':
          description: Access is forbidden.
        '409':
          description: The request conflicts with the current state of the server.
        '429':
          description: Client error
          headers:
            x-correlation-id:
              required: true
              schema:
                type: string
            retry-after:
              required: true
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/iov42.Responses.Response400'
        '500':
          description: InternalServerError
          headers:
            x-correlation-id:
              required: true
              schema:
                type: string
      tags:
        - Messages
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateMessageRequest'
components:
  parameters:
    MessageQuery.channel:
      name: channel
      in: query
      required: false
      description: The channel for the messages.
      schema:
        type: string
      explode: false
    MessageQuery.count:
      name: count
      in: query
      required: true
      description: The number of messages to retrieve. (default is 10)
      schema:
        type: integer
        format: int32
      explode: false
    MessageQuery.entity:
      name: entity
      in: query
      required: true
      description: The sender/recipient to filter on. Depends on the sent flag.
      schema:
        type: string
      explode: false
    MessageQuery.fromTimestamp:
      name: fromTimestamp
      in: query
      required: true
      description: The earliest timestampe to filter on
      schema:
        type: string
        format: date-time
      explode: false
    MessageQuery.lastId:
      name: lastId
      in: query
      required: true
      description: The id of the last message previously fetched
      schema:
        type: integer
        format: int64
      explode: false
    MessageQuery.messageType:
      name: messageType
      in: query
      required: false
      description: The message type to filter on
      schema:
        type: string
      explode: false
    MessageQuery.schemaVersion:
      name: schemaVersion
      in: query
      required: false
      description: The schema version to filter on
      schema:
        type: string
      explode: false
    MessageQuery.sent:
      name: sent
      in: query
      required: true
      description: Display sent messages
      schema:
        type: boolean
      explode: false
    MessageQuery.toTimestamp:
      name: toTimestamp
      in: query
      required: true
      description: The latest timestamp to filter on
      schema:
        type: string
        format: date-time
      explode: false
    iov42.Headers.RequestHeaderBase:
      name: x-correlation-id
      in: header
      required: false
      schema:
        type: string
  schemas:
    BaseMessage:
      type: object
      required:
        - messageType
        - schemaVersion
        - payload
      properties:
        messageType:
          type: string
          description: The message type contained in the payload.
        schemaVersion:
          type: string
          description: The schema version of the message type.
        payload:
          type: string
          contentEncoding: base64
          description: The base64 encoded message payload.
    CreateMessageRequest:
      type: object
      required:
        - recipient
        - messageType
        - schemaVersion
        - payload
      properties:
        recipient:
          type: integer
          format: int32
          description: The intended recipient for the message
        messageType:
          type: string
          description: The message type contained in the payload.
        schemaVersion:
          type: string
          description: The schema version of the message type.
        payload:
          type: string
          contentEncoding: base64
          description: The base64 encoded message payload.
      description: ''
    Message:
      type: object
      required:
        - id
        - from
        - to
        - timestamp
      properties:
        id:
          type: integer
          format: int32
          description: The id assigned by the messaging service.
        from:
          type: integer
          format: int32
          description: The sender of the message.
        to:
          type: integer
          format: int32
          description: Who the message is to be delivered to.
        timestamp:
          type: string
          format: date-time
          description: The UTC timestamp of when the message was received.
      allOf:
        - $ref: '#/components/schemas/BaseMessage'
    MessageRequest:
      type: object
      required:
        - recipient
      properties:
        recipient:
          type: integer
          format: int32
          description: The intended recipient for the message
      allOf:
        - $ref: '#/components/schemas/BaseMessage'
    iov42.Responses.Errors:
      type: object
      allOf:
        - type: array
          items:
            type: string
    iov42.Responses.Response400:
      type: object
      required:
        - body
      properties:
        body:
          $ref: '#/components/schemas/iov42.Responses.Errors'
