openapi: 3.0.1
info:
  title: Media 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:
  /media:
    get:
      tags:
        - Media
      summary: Get a list of media files
      operationId: list
      parameters:
        - name: X-Scope-OrgID
          in: header
          description: Scope header
          required: true
          schema:
            type: string
        - name: ids
          in: query
          description: Comma-separated list of media file identifiers
          schema:
            type: array
            items:
              type: string
        - name: cursor
          in: query
          description: Paging cursor
          schema:
            type: string
            format: byte
        - name: direction
          in: query
          description: Paging direction
          schema:
            $ref: '#/components/schemas/PagingCommand.Direction'
        - name: pageSize
          in: query
          description: Page size
          schema:
            maximum: 100
            minimum: 1
            type: integer
        - name: Api-Version
          in: header
          description: API version
          schema:
            type: string
      responses:
        '200':
          description: Successfully returned media files list
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Page_Object_'
        '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:
        - Media
      summary: Upload a file
      operationId: upload
      parameters:
        - name: X-Scope-OrgID
          in: header
          description: Scope header
          required: true
          schema:
            type: string
        - name: User-ID
          in: header
          description: Current user identifier
          schema:
            type: string
        - name: Api-Version
          in: header
          description: API version
          schema:
            type: string
      requestBody:
        content:
          multipart/form-data:
            schema:
              properties:
                file:
                  type: string
                  format: binary
                metadata:
                  type: string
                  nullable: true
            encoding:
              file:
                contentType: application/octet-stream
      responses:
        '200':
          description: Successfully uploaded a file
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MediaId'
        '400':
          description: Incorrect payload
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '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'
    delete:
      tags:
        - Media
      summary: Delete all media files for the current scope
      operationId: deleteAll
      parameters:
        - name: X-Scope-OrgID
          in: header
          description: Scope header
          required: true
          schema:
            type: string
        - name: Api-Version
          in: header
          description: API version
          schema:
            type: string
      responses:
        '204':
          description: Successfully deleted all media files from a scope
        '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'
  /media/{id}:
    get:
      tags:
        - Media
      summary: Download a file
      operationId: download
      parameters:
        - name: X-Scope-OrgID
          in: header
          description: Scope header
          required: true
          schema:
            type: string
        - name: id
          in: path
          description: Media file identifier
          required: true
          schema:
            type: string
            format: uuid
        - name: Api-Version
          in: header
          description: API version
          schema:
            type: string
      responses:
        '200':
          description: download 200 response
          content:
            application/json:
              schema:
                type: object
        '303':
          description: >-
            A redirection to the media file download URL, which is valid for 5
            minutes
          headers:
            Location:
              description: Download URL
              schema:
                type: string
        '401':
          description: Authorization information is missing or invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '404':
          description: Media file not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '500':
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
    delete:
      tags:
        - Media
      summary: Delete a media file
      operationId: delete
      parameters:
        - name: X-Scope-OrgID
          in: header
          description: Scope header
          required: true
          schema:
            type: string
        - name: id
          in: path
          description: Media file identifier
          required: true
          schema:
            type: string
            format: uuid
        - name: Api-Version
          in: header
          description: API version
          schema:
            type: string
      responses:
        '204':
          description: Successfully deleted media file
        '401':
          description: Authorization information is missing or invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '404':
          description: Media file not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JsonError'
        '500':
          description: Unexpected error
          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
    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
    MediaId:
      required:
        - id
      type: object
      properties:
        id:
          type: string
          format: uuid
      description: DTO class representing media file identifier.
    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
    Page_Object_:
      required:
        - data
        - paging
      type: object
      properties:
        data:
          type: array
          items:
            type: object
        paging:
          $ref: '#/components/schemas/PagingResponse'
      description: DTO class representing a page of data with paging information.
    PagingCommand.Direction:
      type: string
      enum:
        - NEXT
        - PREVIOUS
    PagingCursor:
      required:
        - firstId
        - firstUploadedAt
        - lastId
        - lastUploadedAt
      type: object
      properties:
        firstUploadedAt:
          type: string
          format: date-time
        lastUploadedAt:
          type: string
          format: date-time
        firstId:
          type: string
          format: uuid
        lastId:
          type: string
          format: uuid
      description: DTO class representing paging cursor
    PagingResponse:
      required:
        - cursor
        - hasNext
        - hasPrevious
      type: object
      properties:
        cursor:
          $ref: '#/components/schemas/PagingCursor'
        hasNext:
          type: boolean
        hasPrevious:
          type: boolean
      description: DTO class representing paging information for the response
    Resource:
      type: object
      properties:
        _links:
          $ref: '#/components/schemas/OptionalMultiValues_Link_'
        _embedded:
          $ref: '#/components/schemas/OptionalMultiValues_Resource_'
