openapi: 3.0.2
info:
  title: File Manager Swagger.
  description: File Manager Swagger.
  contact:
    email: auradev@tid.es
  version: 10.26.0
tags:
  - name: file-manager
    description: General api operations
  - name: file-handling
    description: Microservice operations
servers:
  - url: "https://localhost:8015"
paths:
  /healthz:
    get:
      tags:
        - file-manager
      description: API Health Check.
      operationId: healthz
      x-router-controller: generic
      responses:
        "200":
          description: OK
          headers: {}
  /metrics:
    get:
      tags:
        - file-manager
      description: Metrics of file manager.
      operationId: metrics
      x-router-controller: generic
      responses:
        "200":
          description: metrics
          content:
            string:
              schema:
                $ref: "#/components/schemas/MetricsMessage"
  /heapStatistics:
    get:
      tags:
        - file-manager
      description: heap usage statistics.
      operationId: heapStatistics
      x-router-controller: generic
      responses:
        "200":
          description: Heap statistics
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/HeapStatisticsResponse"
  /heapSnapshot:
    get:
      tags:
        - file-manager
      description: Generate heap snapshot.
      operationId: heapSnapshot
      x-router-controller: generic
      responses:
        "200":
          description: Heap snapshot generated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/HeapSnapshotResponse"
  /shutdown:
    get:
      tags:
        - file-manager
      description: Wait untill shutdown (kubernetes lifecycle).
      operationId: shutdown
      x-router-controller: generic
      responses:
        "200":
          description: Shutdown response
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ShutdownResponse"
  /aura-services/v1/files:
    post:
      tags:
        - file-handling
      summary: "Upload files from links"
      description:
        "Receives an array of file urls complemented with an upload name/path, if path is not present a path will be generated.
        It will respond immediately after basic checks and process afterwards the data. When a response is ready it will be sent to the url specified in callback parameter"
      operationId: uploadAndValidateFiles
      x-router-controller: file
      parameters:
        - name: correlator
          in: header
          required: false
          description: Request identifier to cross logs in all systems. If not set a new one is generated and sent in the response.
          schema:
            type: string
            format: uuid
      requestBody:
        description: Data needed to process the call and an array of file urls and paths where they are going to be stored inside local repository
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Files"
        required: true
      responses:
        "204":
          description: Successful operation
        "400":
          $ref: "#/components/responses/InvalidRequest"
        "405":
          $ref: "#/components/responses/NotAllowed"
        "404":
          $ref: "#/components/responses/NotFound"
        "500":
          $ref: "#/components/responses/InternalError"
      x-codegen-request-body-name: body
      callbacks:
        responseReady:
          "{$request.body#/callback}":
            post:
              description: Url and security checks
              parameters:
                - name: correlator
                  in: header
                  required: false
                  description: Request identifier to cross logs in all systems.
                  schema:
                    type: string
                    format: uuid
              requestBody:
                description: Local storage file urls and type/size checks
                content:
                  application/json:
                    schema:
                      $ref: "#/components/schemas/PayloadResponse"
                required: true
              responses:
                "200":
                  description: OK
  /dapr/subscribe:
     get:
       tags:
         - file-manager
       description: File manager to set Subscription Events.
       operationId: daprSubscriptions
       x-router-controller: generic
       responses:
         '200':
           description: OK
           headers: { }
  /dapr/processConfigurationChannelEvents:
    post:
      tags:
        - file-manager
      description: File manager to manage Channel Configuration Events.
      operationId: processConfigurationChannelEvents
      x-router-controller: generic
      responses:
        '200':
          description: OK
          headers: { }
components:
  responses:
    InvalidRequest:
      description: Incoming HTTP request format is not valid
      headers:
        correlator:
          description: Correlation id for the different services
          schema:
            type: string
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/AuraError"
    InternalError:
      description: Unexpected internal error
      headers:
        correlator:
          description: Correlation id for the different services
          schema:
            type: string
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/AuraError"
    NotFound:
      description: Request resource not found
      headers:
        correlator:
          description: Correlation id for the different services
          schema:
            type: string
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/AuraError"
    NotAllowed:
      description: Method not allowed
      headers:
        correlator:
          description: Correlation id for the different services
          schema:
            type: string
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/AuraError"
  schemas:
    Files:
      required:
        - files
        - channelId
        - fromId
        - conversationId
        - messageId
        - responseVersion
      type: object
      properties:
        channelId:
          type: string
          format: uuid
          description: channel identifier of request
        fromId:
          type: string
          description: fromId identifier
        conversationId:
          type: string
          description: Conversation identifier of request
        messageId:
          type: string
          description: Unique message identifier, it is also callback identifier
        callback:
          type: string
          format: url
          description: Callback url base, the complete url will be built using the other parameters, if callback not present, it will be build using local configuration
        responseVersion:
          type: string
          description: Version in which the response is expected
        files:
          type: array
          items:
            $ref: "#/components/schemas/FileData"
          description: Url where file to upload is located
    FileData:
      type: object
      required:
        - url
      properties:
        url:
          type: string
          description: file url
        name:
          type: string
          description: optional file name
        text:
          type: string
          description: optional file text
        contentType:
          type: string
          description: optional file content type
    AuraError:
      type: object
      description: Error response
      properties:
        code:
          type: string
          description: Unique id of the error
        message:
          type: string
          description: Specific and descriptive text of the error
    PayloadResponse:
      type: object
      required:
        - payload
      properties:
        payload:
          $ref: "#/components/schemas/Attachments"
        user_id:
          type: string
        creation_date:
          type: string
          format: date-time
    Attachments:
      type: object
      required:
        - attachments
      properties:
        attachments:
          type: array
          items:
            $ref: "#/components/schemas/Attachment"
          description: List of attachments data after processed (showing local repository url, errors and validations result)
    Attachment:
      type: object
      required:
        - contentType
        - content
      properties:
        contentUrl:
          type: string
          description: Url to uploaded file inside local respository
        contentType:
          type: string
          description: Real mime type of file
        name:
          type: string
          description: Temporary repository file name
        content:
          $ref: "#/components/schemas/AttachmentContent"
    AttachmentContent:
      type: object
      required:
        - processed
        - typeValidation
        - sizeValidation
        - status
      properties:
        processed:
          type: boolean
          description: boolean flag that shows that file has been processed inside microservice
        text:
          type: string
          description: optional file text
        typeValidation:
          $ref: "#/components/schemas/TypeValidation"
        sizeValidation:
          $ref: "#/components/schemas/SizeValidation"
        status:
          type: array
          items:
            $ref: "#/components/schemas/CodeResponse"
          description: Array of after process status, it can contain multiple errors
    TypeValidation:
      type: object
      required:
        - valid
        - value
      description: File real type and type validation
      properties:
        valid:
          type: boolean
          description: Boolean variable that says if file meets type restrictions
        value:
          type: string
          description: Real file type.
    SizeValidation:
      type: object
      required:
        - valid
        - value
      description: File size and size validation
      properties:
        valid:
          type: boolean
          description: Boolean variable that says if file meets size restrictions
        value:
          type: number
          description: File size in bytes.
    CodeResponse:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          enum:
            [
              "ERROR.VALIDATION.TYPE",
              "ERROR.VALIDATION.SIZE",
              "OK",
              "ERROR.UPLOAD",
              "ERROR.MISSING.CHANNEL.CONFIG",
            ]
          description: "response code:\n* ERROR.VALIDATION.TYPE:ErrorValidationType\n* ERROR.VALIDATION.SIZE:ErrorValidationSize\n* ERROR.UPLOAD:ErrorUpload\n* ERROR.MISSING.CHANNEL.CONFIG:ErrorMissingChannelConfig\n* OK:Ok"
        message:
          type: string
          description: response message
    MetricsMessage:
      type: object
    HeapStatisticsResponse:
      type: object
      properties:
        total_heap_size:
          type: number
          description: Total heap size
        total_heap_size_executable:
          type: number
          description: Total heap size executable
        total_physical_size:
          type: number
          description: Total physical size
        total_available_size:
          type: number
          description: Total available size
        used_heap_size:
          type: number
          description: Used heap size
        heap_size_limit:
          type: number
          description: Heap size limit
        malloced_memory:
          type: number
          description: Malloced memory
        peak_malloced_memory:
          type: number
          description: Peak malloced memory
        does_zap_garbage:
          type: number
          description: Does zap garbage
        number_of_native_contexts:
          type: number
          description: Number of native contexts
        number_of_detached_contexts:
          type: number
          description: Number of detached contexts
    HeapSnapshotResponse:
      type: object
      properties:
        status:
          type: string
          description: Snapshot creation and upload status
        description:
          type: string
          description: Status description
    ShutdownResponse:
      type: object
      properties:
        status:
          type: string
          description: shutdown status

