asyncapi: 2.0.0
info:
  title: 156 API
  version: '1.0.0'
  description: issue 156 anonymized API

defaultContentType: application/json

channels:
  'request.env':
    description: The topic on which some events may be produced and consumed
    parameters:
      env:
        $ref: '#/components/parameters/env'
    publish:
      operationId: installInternetExchangePort
      message:
        $ref: '#/components/messages/InstallRequest'
  'response.env':
    description: The topic on which some events may be produced and consumed
    parameters:
      env:
        $ref: '#/components/parameters/env'
    subscribe:
      operationId: receiveInternetExchangePortsStatus
      message:
        oneOf:
          - $ref: '#/components/messages/Response'

components:
  messages:
    InstallRequest:
      name: InstallRequest
      title: Request
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/Headers'
      payload:
        $ref: "#/components/schemas/RequestPayload"
    Response:
      name: Response
      title:  Response
      summary: Check port status
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/Headers'
      payload:
        $ref: "#/components/schemas/ResponsePayload"

  schemas:
    uuid:
      type: string
      format: uuid
    timestamp:
      type: string
      format: date-time
      example: 2022-08-14T12:03:33.000Z
    actionType:
      type: string
      enum:
        - INSTALL
      description: Type of the action
    eventType:
      type: string
      enum:
        - STARTED
        - VALIDATED
        - COMPLETED
        - FAILED
      description: Type of the event
      example: COMPLETED
    RequestPayload:
      type: object
      required:
        - timestamp
        - actionType
        - uuid
        - data
      properties:
        uuid:
          $ref: '#/components/schemas/uuid'
          description: ID of the event
        timestamp:
          $ref: '#/components/schemas/timestamp'
          description: Timestamp of the event
        actionType:
          $ref: '#/components/schemas/actionType'
        data:
          $ref: '#/components/schemas/InstallRequestData'
    ResponsePayload:
      type: object
      required:
        - timestamp
        - eventType
        - uuid
        - data
      properties:
        uuid:
          $ref: '#/components/schemas/uuid'
          description: ID of the event
        timestamp:
          $ref: '#/components/schemas/timestamp'
          description: Timestamp of the event
        eventType:
          $ref: '#/components/schemas/eventType'
        data:
          $ref: '#/components/schemas/ResponseData'
    InstallRequestData:
      type: object
      description:  Install data
      required:
        - gtId
        - activity
      properties:
        gtId:
          type: string
          example: ID-1234567
          description: ID of the transaction
        activity:
          $ref: '#/components/schemas/activity'
    ResponseData:
      type: object
      required:
        - gtId
        - activity
        - retryable
      properties:
        gtId:
          type: string
          example: ID-1232456
          description: ID of the transaction
        activity:
          required:
            - id
          properties:
            id:
              $ref: '#/components/schemas/activityId'
            retryable:
              type: boolean
              description: Determines whether can be retied
            order:
              $ref: '#/components/schemas/order'
            ipV4Address:
              type: string
              example: 127.0.22.1
              description: Allocated IPv4
            ipV6Address:
              type: string
              example: 4422:3311:0:2:0:2:acba:1
              description: Allocated IPv6
        discrepanciesIpV4:
          type: array
          items:
            $ref: '#/components/schemas/discrepancyIpV4'
          description: IPv4 addresses in use to be investigated. Only available for COMPLETED and FAILED eventTypes
        discrepanciesIpV6:
          type: array
          items:
            $ref: '#/components/schemas/discrepancyIpV6'
          description: IPv6 addresses in use to be investigated. Only available for COMPLETED and FAILED eventTypes
        errors:
          $ref: '#/components/schemas/errors'
    errors:
      type: array
      minItems: 1
      items:
        $ref: '#/components/schemas/error'
    discrepancyIpV4:
      type: object
      required:
        - address
        - failedValidations
      properties:
        addressIpV4:
          type: string
          example: 8.8.8.8
          description: IPv4 address that was found to be in use.
        reverseDnsV4:
          type: string
          example: www.google.com
          description: Reverse DNS address
        failedValidations:
          type: array
          items:
            $ref: '#/components/schemas/failedValidation'
    discrepancyIpV6:
      type: object
      required:
        - address
        - failedValidations
      properties:
        addressIpV6:
          type: string
          example: 1111:6b8:2233:3c:123:3
          description: IPv6 addres that was found to be in use.
        reverseDnsV6:
          type: string
          example: 3.3.3.3.3.2.2.2.2.2.1.1.1.1.0.0.0.0.0.0
          description: Reverse DNS address.
        failedValidations:
          type: array
          items:
            $ref: '#/components/schemas/failedValidation'
    failedValidation:
      type: object
      required:
        - validation
      properties:
        validation:
          type: string
          descrition: Identifies which validation failed while checking address availability
          enum:
            - CLIENT
            - PORT
            - ROUTE_SERVER
            - IP
            - ALLOCATION_FAILED
        message:
          type: string
          description: Detailed reason why address is considered to be in use.
    activity:
      type: object
      required:
        - id
        - order
        - account
        - config
        - asn
        - reverseDnsV4
        - reverseDnsV6
        - location
        - physicalPorts
      properties:
        id:
          $ref: '#/components/schemas/activityId'
        type:
          $ref: '#/components/schemas/activityType'
        order:
          $ref: '#/components/schemas/order'
        account:
          $ref: '#/components/schemas/account'
        asn:
          $ref: '#/components/schemas/asn'
        reverseDnsV4:
          $ref: '#/components/schemas/dns'
        reverseDnsV6:
          $ref: '#/components/schemas/dns'
        location:
          $ref: '#/components/schemas/location'
        lag:
          $ref: '#/components/schemas/lag'
        encapsulation:
          $ref: '#/components/schemas/encapsulation'
        peering:
          $ref: '#/components/schemas/peering'
        physicalPorts:
          type: array
          items:
            $ref: '#/components/schemas/physicalPort'
        macs:
          type: array
          items:
            $ref: '#/components/schemas/mac'
    encapsulation:
      type: object
      required:
        - type
      properties:
        type:
          $ref: '#/components/schemas/encapsulationType'
    peering:
      type: object
      required:
        - type
        - state
      properties:
        type:
          $ref: '#/components/schemas/peeringType'
        state:
          $ref: '#/components/schemas/peeringState'
    lag:
      type: object
      required:
        - groupId
        - type
      properties:
        code:
          $ref: '#/components/schemas/lagGroupId'
        type:
          $ref: '#/components/schemas/lagType'
    location:
      type: object
      required:
        - code
        - type
      properties:
        code:
          $ref: '#/components/schemas/locationCode'
        type:
          $ref: '#/components/schemas/locationType'
    physicalPort:
      type: object
      required:
        - id
      properties:
        id:
          $ref: '#/components/schemas/portId'
        crossConnectId:
          $ref: '#/components/schemas/crossConnectId'
    crossConnectId:
      type: string
      example: 2345678-B
      description: Serial Cable ID
    account:
      type: object
      required:
        - number
      properties:
        number:
          $ref: '#/components/schemas/accountNumber'
    port:
      type: object
      required:
        - id
        - crossConnectId
      properties:
        id:
          $ref: '#/components/schemas/portId'
        crossConnectId:
          $ref: '#/components/schemas/crossConnectId'
    encapsulationType:
      type: string
      enum:
        - UNTAGGED
        - DOT
      example: UNTAGGED
      description: Encapsulation Type
    asn:
      type: integer
      description: Autonomous System Number
    dns:
      type: string
      example: www.google.com
      description: Reverse DNS
    peeringType:
      type: string
      enum:
        - PRIVATE
        - PUBLIC
      example: PRIVATE
      description: Peering Type
    peeringState:
      type: string
      enum:
        - PRE-TURN-UP
        - TURN-UP
        - ACTIVE
      example: PRE-TURN-UP
      description: Peering Type
    locationCode:
      type: string
      example: ES
      description: Code of the location dependent on its type
    locationType:
      type: string
      enum:
        - EU
      example: EU
      description: Location type
    accountNumber:
      type: string
      example: 20999
      description: Customer account number
    portId:
      type: integer
      example: 8080
      description: port ID
    activityId:
      type: string
      pattern: '^[0-9]*$'
      example: 716093143
      description: ID of the order activity
    mac:
      type: string
      pattern: '^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$'
      example: 3F-F1-29-16-B3-42
      description: Media Access Control Address
    activityType:
      type: string
      enum:
        - INSTALL
      default: INSTALL
      description: Type of the order activity
    order:
      type: object
      required:
        - number
      properties:
        number:
          $ref: '#/components/schemas/orderNumber'
    orderNumber:
      type: string
      pattern: '^[0-9]*$'
      example: 656015405
      description: ID of the order

    error:
      type: object
      description: Error entity
      required:
        - code
        - message
        - details
      properties:
        code:
          type: string
          example: Err-1
          description: Error Code
        message:
          type: string
          description: Error Message
        details:
          type: string
          description: Error Details

  parameters:
    env:
      description: Environment
      schema:
        type: string
        enum:
          - prod
          - dev
          - uat
          - qa

  messageTraits:
    Headers:
      headers:
        type: object
        required:
          - messageKey
          - CorrelationId
        properties:
          messageKey:
            $ref: '#/components/schemas/uuid'
            description: Message Key
          CorrelationId:
            $ref: '#/components/schemas/uuid'
            description: Correlation UUID
          Version:
            type: string
            enum:
              - v1
              - v2
            description: Version