openapi: 3.0.1
info:
  title: Integration service
  contact:
    name: co.brick
    url: https://cobrick.com
    email: aiops@cobrick.com
  license:
    name: Commercial
    url: https://cobrick.com
  version: v1
servers:
  - url: https://app.observe.digital/api/v1
    description: Production environment
  - url: https://stage.observe.digital/api/v1
    description: Staging environment
  - url: http://localhost:8080
    description: Local environment
paths:
  /integrations:
    get:
      tags:
        - Integrations
      summary: Get the list of integrations and their link statuses
      operationId: getIntegrations
      parameters:
        - name: X-Scope-OrgID
          in: header
          description: Tenant header
          schema:
            type: string
        - name: Api-Version
          in: header
          description: API version
          schema:
            type: string
      responses:
        '200':
          description: Successfully returned integrations
          content:
            application/json:
              schema:
                minItems: 0
                type: array
                items:
                  $ref: '#/components/schemas/Integration'
        '401':
          description: Authorization information is missing or invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
    post:
      tags:
        - Integrations
      summary: Install integration with an external system
      operationId: install
      parameters:
        - name: X-Scope-OrgID
          in: header
          description: Tenant header
          schema:
            type: string
        - name: system
          in: query
          description: External system name
          required: true
          schema:
            type: string
        - name: Api-Version
          in: header
          description: API version
          schema:
            type: string
      responses:
        '200':
          description: Installation successful
          content:
            text/plain:
              schema:
                type: string
        '403':
          description: Operation not permitted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '422':
          description: Cannot install integration
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
    delete:
      tags:
        - Integrations
      summary: Remove an integration with an external system
      operationId: uninstall
      parameters:
        - name: X-Scope-OrgID
          in: header
          description: Tenant header
          schema:
            type: string
        - name: system
          in: query
          description: External system name
          required: true
          schema:
            type: string
        - name: Api-Version
          in: header
          description: API version
          schema:
            type: string
      responses:
        '200':
          description: Removal successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
  /integrations/oauth/callback:
    get:
      tags:
        - OAuth
      summary: OAuth 2.0 link flow callback
      operationId: oauthCallback
      parameters:
        - name: X-Scope-OrgID
          in: header
          description: Tenant header
          schema:
            type: string
        - name: code
          in: path
          description: An authorization code to be exchanged for an access token
          required: true
          schema:
            type: string
        - name: state
          in: path
          description: A unique identifier of the flow, the same as in the initial request
          required: true
          schema:
            type: string
            format: uuid
        - name: Api-Version
          in: header
          description: API version
          schema:
            type: string
      responses:
        '200':
          description: oauthCallback 200 response
        '301':
          description: Callback successful, redirect to the integrations UI view
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '404':
          description: Integration not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '422':
          description: Cannot handle callback
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '501':
          description: Callback not implemented for given external system
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
components:
  schemas:
    AbstractResource_JsonError_:
      type: object
      properties:
        _links:
          type: object
          additionalProperties: true
        _embedded:
          type: object
          additionalProperties:
            type: array
            items:
              $ref: '#/components/schemas/Resource'
    Charset:
      type: object
      properties:
        registered:
          type: boolean
    Integration:
      required:
        - system
      type: object
      properties:
        system:
          type: string
        status:
          nullable: true
          allOf:
            - $ref: '#/components/schemas/Integration.Status'
      description: A model class representing integration with an external system.
    Integration.Status:
      type: string
      enum:
        - INITIATED
        - LINKED
    JsonError:
      type: object
      allOf:
        - $ref: '#/components/schemas/AbstractResource_JsonError_'
        - required:
            - message
          properties:
            _links:
              type: object
              additionalProperties: true
            _embedded:
              type: object
              additionalProperties:
                type: array
                items:
                  $ref: '#/components/schemas/Resource'
            message:
              type: string
            logref:
              type: string
              nullable: true
            path:
              type: string
              nullable: true
    MediaType:
      required:
        - name
      type: object
      properties:
        name:
          type: string
        type:
          type: string
        subtype:
          type: string
        extension:
          type: string
        parameters:
          $ref: '#/components/schemas/OptionalValues_String_'
        quality:
          type: string
        qualityAsNumber:
          type: number
        version:
          type: string
        charset:
          nullable: true
          allOf:
            - $ref: '#/components/schemas/Charset'
        textBased:
          type: boolean
    OptionalMultiValues_Link_:
      $ref: '#/components/schemas/OptionalValues_List_Link__'
    OptionalMultiValues_Resource_:
      $ref: '#/components/schemas/OptionalValues_List_Resource__'
    OptionalValues_List_Link__:
      type: object
      properties:
        empty:
          type: boolean
    OptionalValues_List_Resource__:
      type: object
      properties:
        empty:
          type: boolean
    OptionalValues_String_:
      type: object
      properties:
        empty:
          type: boolean
    Resource:
      type: object
      properties:
        _links:
          $ref: '#/components/schemas/OptionalMultiValues_Link_'
        _embedded:
          $ref: '#/components/schemas/OptionalMultiValues_Resource_'
