"openapi": "3.0.0",
  "info": {
    "title": "Document Storage Microservice API",
    "description": "Temenos Document Storage Microservice",
    "version": "1.0.0-dev"
  },
  "contact": {
    "email": "dliu@temenos.com"
  },
  "externalDocs": {
	"url": "https://docs.temenos.com/docs/Solutions/Infinity/Microservices/Modules/Microservices/document-storage/misc/overview.html",
	"description": "Find more information here"
  },
  "tags": [
    {
      "name": "admins",
      "description": "Operations available to the internal admins"
    },
    {
      "name": "owners",
      "description": "Operations available to the document owner systems"
    }
  ],
  "servers": [
    {
      "url": "http://localhost:8090/ms-document-api/api/v1.0.0"
    }
  ],
  "paths": {
    "/documents/info/{documentId}": {
      "get": {
        "operationId": "getDocumentInfo",
        "summary": "Get Document info (For internal use)",
        "tags": [
          "admins"
        ],
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "description": "JWT token",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "documentId",
            "in": "path",
            "description": "Document Id",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Document Info Requested",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentInfo"
                }
              }
            }
          },
          "404": {
            "description": "Document Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NoDocumentFoundErrorResponse"
                }
              }
            }
          },
          "default": {
            "description": "Standard Error Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StandardErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/documents/": {
      "post": {
        "operationId": "uploadDocument",
        "summary": "Upload a new document",
        "tags": [
          "owners"
        ],
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "description": "JWT token",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "ownersystemid",
            "in": "header",
            "description": "Owner System ID (Fabric Application ID)",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "userid",
            "in": "header",
            "description": "User ID (This is only used as a workaround to support sending userId directly when JWT token check in unavailable at event stream channel (For example, when Receipting MS sends an upload message from event stream). You should NEVER provide this value in REST API case since the userId is retrieved from JWT payload as in sub field. This field will be removed after proper JWT token check gets added for the event stream channel.",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "description": "file to upload",
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/DocumentUpload"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Document Upload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadDocumentResponse"
                }
              }
            }
          },
          "400": {
            "description": "File Size Limit Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileSizeLimitErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "File Has Virus Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileHasVirusErrorResponse"
                }
              }
            }
          },
          "default": {
            "description": "Standard Error Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StandardErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/documents/{documentId}": {
      "get": {
        "operationId": "downloadDocument",
        "summary": "Download a document",
        "tags": [
          "owners"
        ],
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "description": "JWT token",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "ownersystemid",
            "in": "header",
            "description": "Owner System ID (Fabric Application ID)",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "documentId",
            "in": "path",
            "description": "Document Id",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Document download as binary file.",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "$ref": "#/components/schemas/DownloadDocumentResponse"
                }
              }
            }
          },
          "404": {
            "description": "Document Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NoDocumentFoundErrorResponse"
                }
              }
            }
          },
          "default": {
            "description": "Standard Error Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StandardErrorResponse"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteDocument",
        "summary": "Delete a document",
        "tags": [
          "owners"
        ],
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "description": "JWT token",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "ownersystemid",
            "in": "header",
            "description": "Owner System ID (Fabric Application ID)",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "documentId",
            "in": "path",
            "description": "Document Id",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Delete the document",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeleteDocumentResponse"
                }
              }
            }
          },
          "404": {
            "description": "Document Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NoDocumentFoundErrorResponse"
                }
              }
            }
          },
          "default": {
            "description": "Standard Error Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StandardErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/documents": {
      "get": {
        "operationId": "searchDocuments",
        "summary": "Search Document(s) info",
        "tags": [
          "owners"
        ],
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "description": "JWT token",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "ownersystemid",
            "in": "header",
            "description": "Owner System ID (Fabric Application ID)",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "description": "Search Metadata as JSON String Object. All Keys must match predefined search metadata when uploading document. For optimized search, provide your most unique key first. Example, {\"transactionId\":\"ABCDEFG\",\"documentType\":\"attachment\"}",
            "required": true,
            "schema": {
              "type": "string"
            },
            "style": "form",
            "explode": true
          }
        ],
        "responses": {
          "200": {
            "description": "Document Info Requested",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchDocumentResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid Search Error Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InvalidSearchErrorResponse"
                }
              }
            }
          },
          "default": {
            "description": "Standard Error Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StandardErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "DeleteDocumentResponse": {
        "type": "object",
        "description": "Delete document response.",
        "properties": {
          "documentId": {
            "type": "string",
            "example": "443b3f1277b2645cffa57ee7bef2ece0"
          },
          "ownerSystemId": {
            "type": "string",
            "example": "443b3f1277b2645cffa57ee7bef2ece0"
          }
        }
      },
      "DocumentDetails": {
        "type": "object",
        "required": [
          "searchMetadata"
        ],
        "properties": {
          "searchMetadata": {
            "type": "object",
            "description": "key-value pair search Metadata defined by the owner system that attaches to this document. Can be used to search the document later [Max 6 key value pair can be provided].",
            "example": {
              "transactionID": "ABCDE",
              "documentType": "attachment",
              "attachmentType": "passport",
              "ownerID": "john.smith"
            }
          },
          "tempSharedFileLocation": {
            "type": "string",
            "description": "A location where the file is temporarly stored to share across. This is mainly to support uploading a file through the event stream by another Microservice like Receipting MS. You don't need this field when uploading directly through documentFile binary.",
            "example": "/receipt-ms/receipt-22.pdf"
          },
          "mimeType": {
            "type": "string",
            "description": "The mime type of the file. This is mainly to support uploading a file through the event stream by another Microservice like Receipting MS. You don't need this field when uploading directly through documentFile binary.",
            "example": "application/pdf"
          }
        }
      },
      "DocumentUpload": {
        "type": "object",
        "required": [
          "documentDetails"
        ],
        "properties": {
          "documentDetails": {
            "$ref": "#/components/schemas/DocumentDetails"
          },
          "documentFile": {
            "type": "string",
            "format": "binary",
            "description": "The actual file binary. In case file is uploaded through the temporary shared location specified in the documentDetails, this field is not required."
          }
        }
      },
      "SearchDocumentMetadata": {
        "description": "document metadata object",
        "properties": {
          "documentId": {
            "type": "string",
            "example": "443b3f1277b2645cffa57ee7bef2ece0"
          },
          "searchMetadata": {
            "description": "key-value pair search Metadata defined by the owner system that attaches to this document.",
            "type": "object",
            "example": {
              "transactionID": "ABCDE",
              "documentType": "attachment",
              "attachmentType": "passport",
              "ownerID": "john.smith"
            }
          }
        },
        "additionalProperties": {
          "type": "string"
        }
      },
      "SearchDocumentResponse": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/SearchDocumentMetadata"
        },
        "example": [
          {
            "documentId": "24ef8b5a-b991-4a3c-bc6a-d089589ec283",
            "searchMetadata": {
              "attachmentType": "passport",
              "documentType": "attachment",
              "ownerId": "john.smith",
              "transactionId": "ABCDE"
            }
          },
          {
            "documentId": "24ef8b5a-b991-4a3c-bc6a-d089589ec284",
            "searchMetadata": {
              "attachmentType": "driverLicenseFront",
              "documentType": "attachment",
              "ownerId": "john.smith",
              "transactionId": "ABCDE"
            }
          },
          {
            "documentId": "24ef8b5a-b991-4a3c-bc6a-d089589ec285",
            "searchMetadata": {
              "attachmentType": "driverLicenseBack",
              "documentType": "attachment",
              "ownerId": "john.smith",
              "transactionId": "ABCDE"
            }
          }
        ]
      },
      "DocumentInfo": {
        "type": "object",
        "required": [
          "documentId",
          "documentName",
          "ownerSystemId",
          "ownerId",
          "fileName",
          "mimeType",
          "filePath",
          "searchMetadata",
          "createdDate",
          "createdBy"
        ],
        "properties": {
          "documentId": {
            "type": "string",
            "example": "a8f26926-5d52-4f28-b0b6-fd39d0b228cb"
          },
          "ownerSystemId": {
            "description": "Owner System ID (Fabric Application ID)",
            "type": "string",
            "example": "443b3f1277b2645cffa57ee7bef2ece0"
          },
          "fileName": {
            "description": "File name",
            "type": "string",
            "example": "passport.jpg"
          },
          "mimeType": {
            "description": "File mime type",
            "type": "string",
            "example": "text/plain"
          },
          "filePath": {
            "description": "File path to the real file.",
            "type": "string",
            "example": "/document-base/25/9a/f5661bfd78a42f9444a0a48234f94e71113b"
          },
          "searchMetadata": {
            "description": "searchMetadata from the owner system that attaches to this document.",
            "type": "object",
            "example": {
              "transactionID": "ABCDE",
              "documentType": "attachment",
              "attachmentType": "passport",
              "ownerID": "john.smith"
            }
          },
          "createdDate": {
            "description": "document created date",
            "type": "string",
            "format": "date",
            "example": "2020-06-29 07:08:27.0"
          },
          "updatedDate": {
            "description": "document updated date (not in use)",
            "type": "string",
            "format": "date",
            "example": "2020-06-29 07:10:27.0"
          },
          "createdBy": {
            "description": "which user id created the document info. (not in use)",
            "type": "string",
            "example": "owner"
          },
          "updatedBy": {
            "description": "which user id last updated the document info. (not in use)",
            "type": "string",
            "example": "owner"
          }
        }
      },
      "OwnerSystem": {
        "type": "object",
        "required": [
          "ownerSystemId",
          "ownerSystemName",
          "description"
        ],
        "properties": {
          "ownerSystemId": {
            "description": "Owner System ID (Fabric Application ID)",
            "type": "string",
            "example": "443b3f1277b2645cffa57ee7bef2ece0"
          },
          "ownerSystemName": {
            "description": "Owner system name",
            "type": "string"
          },
          "description": {
            "description": "Owner system description.",
            "type": "string"
          }
        }
      },
      "DownloadDocumentResponse": {
        "type": "object"
      },
      "InDevelopResponse": {
        "properties": {
          "message": {
            "type": "string",
            "example": "This feature is under development"
          }
        }
      },
      "UploadDocumentResponse": {
        "properties": {
          "documentId": {
            "type": "string",
            "example": "f003920e-0575-4431-b9a5-f82e992a3187"
          },
          "ownerSystemId": {
            "type": "string",
            "example": "443b3f1277b2645cffa57ee7bef2ece0"
          }
        }
      },
      "StandardErrorSchema": {
        "type": "object",
        "properties": {
          "code": {
            "description": "Error code",
            "type": "string",
            "example": ""
          },
          "message": {
            "description": "Error message",
            "type": "string",
            "example": "Invocation of function implementation com.temenos.microservice.document.function.UploadDocumentImpl failed"
          }
        }
      },
      "StandardErrorResponse": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/StandardErrorSchema"
        }
      },
      "NoDocumentFoundErrorSchema": {
        "type": "object",
        "properties": {
          "code": {
            "description": "Error code",
            "type": "string",
            "example": "NO_DOCUMENT_FOUND"
          },
          "message": {
            "description": "Error message",
            "type": "string",
            "example": "71188dc4-ca4e-49eb-95d4-246167f5712d document not found."
          }
        }
      },
      "NoDocumentFoundErrorResponse": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/NoDocumentFoundErrorSchema"
        }
      },
      "FileSizeLimitErrorSchema": {
        "type": "object",
        "properties": {
          "code": {
            "description": "Error code",
            "type": "string",
            "example": "EXCEED_MAX_FILE_SIZE_LIMIT"
          },
          "message": {
            "type": "string",
            "example": "Exceed max file size limit of filesize MB."
          }
        }
      },
      "FileSizeLimitErrorResponse": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/FileSizeLimitErrorSchema"
        }
      },
      "FileHasVirusErrorSchema": {
        "type": "object",
        "properties": {
          "code": {
            "description": "Error code",
            "type": "string",
            "example": "FILE_HAS_VIRUS"
          },
          "message": {
            "type": "string",
            "example": "The file is rejected, it might contain virus."
          }
        }
      },
      "FileHasVirusErrorResponse": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/FileHasVirusErrorSchema"
        }
      },
      "InvalidSearchErrorSchema": {
        "type": "object",
        "properties": {
          "code": {
            "description": "Error code",
            "type": "string",
            "example": "INVALID_SEARCH"
          },
          "message": {
            "description": "Error message",
            "type": "string",
            "example": "Unable to search document. Search metadata is not valid JSON string."
          }
        }
      },
      "InvalidSearchErrorResponse": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/InvalidSearchErrorSchema"
        }
      }
    }
  }

