openapi: 3.1.0

info:
  title: Webhooks API
  version: '1.0'

paths:
  /session.event.JSError:
    post:
      summary: JSerror
      description: |
        ---
        title: JSError
        group: [EVENT TYPES, session.event]
        ---
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SessionEventJSErrorPayload'
      responses:
        '200':
          description: Event handled successfully

  /session.event.NetError:
    post:
      summary: NetError
      description: |
        ---
        title: NetError
        group: [EVENT TYPES, session.event]
        ---
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SessionEventNetErrorPayload'
      responses:
        '200':
          description: Event handled successfully

  /session.event.ErrorClick:
    post:
      summary: ErrorClick
      description: |
        ---
        title: ErrorClick
        group: [EVENT TYPES, session.event]
        ---
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SessionEventErrorClickPayload'
      responses:
        '200':
          description: Event handled successfully

  /session.event.RageClick:
    post:
      summary: Handle session event
      description: |
        ---
        title: RageClick
        group: [EVENT TYPES, session.event]
        ---
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SessionEventRageClickPayload'
      responses:
        '200':
          description: Event handled successfully

  /session.event.Custom:
    post:
      summary: Handle session event
      description: |
        ---
        title: Custom
        group: [EVENT TYPES, session.event]
        ---
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SessionEventCustomPayload'
      responses:
        '200':
          description: Event handled successfully

components:
  schemas:
    CommonProperties:
      type: object
      properties:
        message_id:
          type: string
        webhook_id:
          type: string
        webhook_type:
          type: string
        api_version:
          type: string
        account_id:
          type: string
        website_id:
          type: string
        created_at:
          type: integer

    CommonPayloadProperties:
      type: object
      properties:
        visitor:
          $ref: '#/components/schemas/Visitor'
        event_name:
          type: string
        time:
          type: integer
        name:
          type: string

    Visitor:
      type: object
      properties:
        id:
          type: string
          description: The unique ID of the visitor
        name:
          type: string
          description: The name of the visitor
        email:
          type: string
          description: The email of the visitor
        params:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
              value:
                type: string
        geolocation:
          type: object
          properties:
            country_code:
              type: string
            city:
              type: string
            region:
              type: string

    JSErrorPayload:
      type: object
      properties:
        count:
          type: integer
        value:
          type: string

    NetErrorPayload:
      type: object
      properties:
        method:
          type: string
        url:
          type: string
        status:
          type: integer

    ErrorClickPayload:
      type: object
      properties:
        message:
          type: string

    RageClickPayload:
      type: object
      properties:
        clicks:
          type: integer

    CustomPayload:
      type: object
      properties:
        properties:
          type: object
          additionalProperties: true

    SessionEventJSErrorPayload:
      allOf:
        - $ref: '#/components/schemas/CommonProperties'
        - type: object
          properties:
            payload:
              allOf:
                - $ref: '#/components/schemas/CommonPayloadProperties'
                - $ref: '#/components/schemas/JSErrorPayload'


    SessionEventNetErrorPayload:
      allOf:
        - $ref: '#/components/schemas/CommonProperties'
        - type: object
          properties:
            payload:
              allOf:
                - $ref: '#/components/schemas/CommonPayloadProperties'
                - $ref: '#/components/schemas/NetErrorPayload'


    SessionEventErrorClickPayload:
      allOf:
        - $ref: '#/components/schemas/CommonProperties'
        - type: object
          properties:
            payload:
              allOf:
                - $ref: '#/components/schemas/CommonPayloadProperties'
                - $ref: '#/components/schemas/ErrorClickPayload'

    SessionEventRageClickPayload:
      allOf:
        - $ref: '#/components/schemas/CommonProperties'
        - type: object
          properties:
            payload:
              allOf:
                - $ref: '#/components/schemas/CommonPayloadProperties'
                - $ref: '#/components/schemas/RageClickPayload'

    SessionEventCustomPayload:
      allOf:
        - $ref: '#/components/schemas/CommonProperties'
        - type: object
          properties:
            payload:
              allOf:
                - $ref: '#/components/schemas/CommonPayloadProperties'
                - $ref: '#/components/schemas/CustomPayload'