asyncapi: 2.0.0

info:
  title: Kafka Messages definition
  version: 1.0.0
  description: Kafka messages specification

channels:
  device-installation-events:
    description: user related events
    bindings:
      kafka:
        cleanup.policy: delete
    publish:
      message:
        oneOf:
          - $ref: '#/components/messages/DeviceInstallationPublished'
          - $ref: '#/components/messages/DeviceInstallationResponsePublished'
    subscribe:
      message:
          $ref: '#/components/messages/DeviceInstallationResponsePublished'

components:
  messages:
    DeviceInstallationPublished:
      name: DeviceInstallationPublished
      title: DeviceInstallationPublished
      summary: Device Installation Published
      schemaFormat: 'application/schema+yaml;version=draft-07'
      payload:
        $ref: 'DeviceInstallationPublished.yaml#/components/schemas/DeviceInstallationPublished'
    DeviceInstallationResponsePublished:
      name: DeviceInstallationResponsePublished
      title: DeviceInstallationResponsePublished
      summary: Device Installation Response Published
      schemaFormat: 'application/schema+yaml;version=draft-07'
      payload:
        $ref: '#/components/schemas/DeviceInstallationResponsePublished'

  schemas:
    DeviceInstallationResponsePublished:
      allOf:
        - $ref: '#/components/schemas/BasicKafkaEnvelope'
        - type: object
          properties:
            data:
              type: object
              required:
                - deviceId
                - id
                - status
              additionalProperties: false
              properties:
                deviceId:
                  $ref: '#/components/schemas/UUID'
                id:
                  $ref: '#/components/schemas/UUID'
                status:
                  $ref: '#/components/schemas/TaskStatus'
                message:
                  type: string
                temperature:
                  type: integer
                  format: int32
                vibration:
                  type: integer
                  format: int64
                floatType:
                  type: number
                  format: float
                doubleType:
                  type: number
                  format: double
                byteType:
                  type: string
                  format: byte

    # ----------------- OTHER schemas -------------------
    Timestamp:
      title: timestamp
      type: string
      pattern: >-
        ^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$
      example: '2017-01-09T08:27:22.222Z'

    UUID:
      type: string
      format: uuid
      example: bd58d14f-fd3e-449c-b60c-a56548190d68

    BasicKafkaEnvelope:
      type: object
      required:
        - id
        - key
        - type
        - generated
        - requestId
      properties:
        id:
          $ref: '#/components/schemas/UUID'
        key:
          type: string
        type:
          type: string
        generated:
          $ref: '#/components/schemas/Timestamp'
        requestId:
          type: string

    TaskStatus:
      type: string
      enum:
        - success
        - error
        - in_progress

