openapi: 3.1.0
info:
  title: TMT API
  description: API working with Test folders in TMT
  version: 1.0.0
paths:
  /api/v2/attachment?filename={filename}&documentModelName={documentName}&pathToField={path}:
    post:
      summary: Upload attachment
      description: >
        Upload attachment to TMT<br/>

        **Notice**: For attachments of types: JPEG, PNG, BMP, WBMP , GIF or SVG,
        thumbnails will be generated with .png extension in 2 configurable
        sizes: small thumbnal and big thumbnail. Only images has
        smallThumbnailUrl  and bigThumbnailUrl  in the response

        <br/> This attachment response then can be used to build the document
        content during the add/modify document operation
      parameters:
        - $ref: '#/components/parameters/ProjectIdHeader'
        - $ref: '#/components/parameters/SubProjectIdHeader'
        - name: filename
          in: path
          description: >-
            s not only attachment identifier the user knows but also with
            correct file extension might be a hint for supporting attachment
            mime type detection more precisely, therefore it is vital for
            attachment handling.
          required: true
          schema:
            type: string
            example: image.png
        - name: documentModelName
          in: path
          description: >-
            is needed for security purposes. The user of this endpoint must have
            the read access to this document.
          required: true
          schema:
            type: string
            example: TestSuite-dm
        - name: pathToField
          in: path
          required: false
          description: >-
            reserved for future, but it is mandatory parameter. Empty string
            could be used.
          schema:
            type: string
            example: /Root/Attachments
      responses:
        '200':
          description: Detail of the uploaded attachment
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UploadedAttachmentResponse'
                examples:
                  $ref: example/UPLOAD_ATTACHMENT-response.json
  /api/v2/rpc (LOAD_THUMBNAIL_URL):
    post:
      summary: Load thumbnails
      description: Load a thumbnail by given attachment id
      parameters:
        - $ref: '#/components/parameters/ProjectIdHeader'
        - $ref: '#/components/parameters/SubProjectIdHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LoadThumbnailUrlRequest'
              examples:
                $ref: example/LOAD_THUMBNAIL_URL-request.json
      responses:
        '200':
          description: >-
            Return stable public URLs (no security will be applied during
            download) which contain caching instructions for the browser.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LoadThumbnailUrlResponse'
                examples:
                  $ref: example/LOAD_THUMBNAIL_URL-response.json
  /api/v2/rpc (LOAD_ATTACHMENT_URL):
    post:
      summary: Load attachment
      description: >-
        Generate expirable public URLs (no security will be applied during
        download) with instruction for the browser not to cache. The expiration
        time is 5 minutes
      parameters:
        - $ref: '#/components/parameters/ProjectIdHeader'
        - $ref: '#/components/parameters/SubProjectIdHeader'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LoadAttachmentUrlRequest'
              examples:
                $ref: example/LOAD_ATTACHMENT_URL-request.json
      responses:
        '200':
          description: Return stable public and expirable URLs
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LoadAttachmentUrlResponse'
                examples:
                  $ref: example/LOAD_ATTACHMENT_URL-response.json
security:
  - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  schemas:
    LoadAttachmentUrlRequest:
      allOf:
        - $ref: '#/components/schemas/RpcRequestWithIdAndJsonRpc'
        - type: object
          required:
            - method
            - params
          properties:
            method:
              type: string
              description: LOAD_ATTACHMENT_URL
            params:
              required:
                - attachmentId
                - docRef
              properties:
                attachmentId:
                  type: string
                  description: attachment id
                docRef:
                  type: string
                  description: >-
                    document reference of the document where the attachmentId
                    assigned. The URL will be provided only for attachments that
                    are already assigned to a document. This check ensures that
                    attachments will be available only to users that have
                    permissions to see the document. This parameter is mandatory
                    for security reasons.
      examples:
        - jsonrpc: '2.0'
          id: 7292c210-c779-44da-a803-925e7211f13c
          method: LOAD_ATTACHMENT_URL
          params:
            attachmentId: 7292c210-c779-44da-a803-925e7211f13c
            docRef: TestCase-dm/656241
    LoadThumbnailUrlRequest:
      allOf:
        - $ref: '#/components/schemas/RpcRequestWithIdAndJsonRpc'
        - type: object
          required:
            - method
            - params
          properties:
            method:
              type: string
              description: LOAD_THUMBNAIL_URL
            params:
              required:
                - attachmentId
              properties:
                attachmentId:
                  type: string
                  description: attachment id
      examples:
        - jsonrpc: '2.0'
          id: LOAD_THUMBNAIL_URL_f7a4cb03-0e73-4843-8c85-42fc58373f76
          method: LOAD_THUMBNAIL_URL
          params:
            attachmentId: 111c7b20-60aa-44b4-b8df-667fe0dfacac
    LoadThumbnailUrlResponse:
      allOf:
        - $ref: '#/components/schemas/RpcResult'
        - type: object
          properties:
            result:
              type: object
              properties:
                smallThumbnailUrl:
                  type: string
                  description: public url for the small thumbnail
                bigThumbnailUrl:
                  type: string
                  description: public url for the big thumbnail
      examples:
        - jsonrpc: '2.0'
          id: LOAD_THUMBNAIL_URL_f7a4cb03-0e73-4843-8c85-42fc58373f76
          result:
            smallThumbnailUrl: >-
              https://demo.q12-tmt.com/cs/download/9c01be12-01ff-4173-9403-6edf670dca50
            bigThumbnailUrl: >-
              https://demo.q12-tmt.com/cs/download/644ee139-4a02-424e-8549-a0f54f4571f2
    LoadAttachmentUrlResponse:
      allOf:
        - $ref: '#/components/schemas/RpcResult'
        - type: object
          properties:
            result:
              type: object
              properties:
                location:
                  type: string
                  description: public url for the attachment but it is expirable
      examples:
        - jsonrpc: '2.0'
          id: 7292c210-c779-44da-a803-925e7211f13c
          result:
            location: >-
              https://demo.q12-tmt.com/cs/download/fb2568f6-ea18-4c37-9956-f7cb0923245e?filename=1731919495027-30b37cef-cb96-4879-a893-c93055a02294.json
    UploadedAttachmentResponse:
      type: object
      description: Represents an attachment with metadata and optional annotations.
      properties:
        attachmentId:
          type: string
          description: Unique identifier for the attachment.
        filename:
          type: string
          description: Name of the file, including the timestamp and extension.
        mimeType:
          type: string
          description: MIME type of the file (e.g., image/png).
        smallThumbnailUrl:
          type: string
          description: URL for the small thumbnail of the attachment.
        bigThumbnailUrl:
          type: string
          description: URL for the large thumbnail of the attachment.
        size:
          type: integer
          description: Size of the file in bytes.
        annotations:
          type: array<string>
          description: A list of annotations associated with the attachment.
      examples:
        - attachmentId: 60b87e2a-f5b5-4540-8335-4f2e4d58b0e0
          filename: 1700559417826-8a9fca09-5dd3-4bf8-9bba-093ac730772e.png
          mimeType: image/png
          smallThumbnailUrl: https://q12-tmt.com/cs/download/ad6be8d7-aa40-45c9-8ea9-2620077319a8
          bigThumbnailUrl: https://q12-tmt.com/cs/download/2d10c4ff-3d39-4c9d-8468-0c04b7dbafe7
          size: 4952
          annotations: []
    Attachment:
      type: object
      properties:
        FileName:
          type: string
          description: Name of the file attached.
        CreatedAt:
          type: string
          format: date-time
          description: Timestamp when the attachment was created.
        UploadOn:
          type: string
          format: date
          description: Date when the file was uploaded.
        OriginalFileName:
          type: string
          description: Original filename as provided during upload.
        UploadBy:
          type: string
          description: Username of the uploader.
        Referenced:
          type: boolean
          description: Indicates if the attachment is referenced elsewhere.
        CopyNumber:
          type: integer
          description: Number of times the attachment has been copied.
        ThumbnailId:
          type: string
          description: Identifier for the attachment’s thumbnail image.
        File:
          $ref: '#/components/schemas/File'
    RpcRequestWithIdAndJsonRpc:
      type: object
      required:
        - id
        - jsonrpc
      properties:
        id:
          type: string
          description: id of the operation
        jsonrpc:
          type: string
          description: must be 2.0
          example: '2.0'
    RpcResult:
      type: object
      properties:
        jsonrpc:
          type: string
          description: request jsonrpc version
        id:
          type: string
          description: id of the operation
        result:
          type: object
    File:
      type: object
      properties:
        content:
          type: string
          nullable: true
          description: Content of the file in base64 format.
        attachment_id:
          type: string
          description: Unique identifier for the attachment.
        internal_filename:
          type: string
          description: Internal storage filename for the attachment.
        original_filename:
          type: string
          description: Original name of the uploaded file.
        size:
          type: integer
          description: Size of the file in bytes.
        mime_type:
          type: string
          description: MIME type of the file.
  parameters:
    ProjectIdHeader:
      name: Project-Id
      in: header
      required: true
      schema:
        type: string
      description: Project Id or the project document reference
    SubProjectIdHeader:
      name: Subproject-Id
      in: header
      required: false
      schema:
        type: string
      description: >-
        Sub Project Id or the project document reference. It might be required
        if you want to access the sub project's resource
