
  "openapi": "3.0.0",
  "info": {
    "title": "Document Storage Microservice API",
    "description": "Temenos Document Storage Microservice",
    "version": "1.0.0"
  },
  "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:8006/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": "documentgroup",
            "in": "header",
            "description": "Document group (Journey ID can be the value of the document group in the format of journey-ownerSystemId-journeyID)",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "description": "file to upload",
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/DocumentUpload"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Document Uploaded",
            "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"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "updateDocument",
        "summary": "Update document (3 actions are supported DELIVERY, ADD_METADATA and UPDATE_METADATA. DELIVERY action is to promote temporary journey document from the Infinity channel to the core banking channel. ADD_METADATA is for adding new search metadata to the existing set of metadata, and the UPDATE_METADATA is for replacing the current set of document search metadata with the new set.)",
        "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": "documentgroup",
            "in": "header",
            "description": "Document group. (For example - journey ID can be the value of the document group in the format of journey-ownerSystemId-journeyID.)",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "description": "Document update body include the document id and new set of search metadata.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentUpdate"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deliver the document",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpdateDocumentResponse"
                }
              }
            }
          },
          "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/{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": "documentgroup",
            "in": "header",
            "description": "Document group. (For example - journey ID can be the value of the document group in the format of journey-ownerSystemId-journeyID.)",
            "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": "documentgroup",
            "in": "header",
            "description": "Document group. (For example - journey ID can be the value of the document group in the format of journey-ownerSystemId-journeyID.)",
            "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": "documentgroup",
            "in": "header",
            "description": "Document group. (For example - journey ID can be the value of the document group in the format of journey-ownerSystemId-journeyID.)",
            "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": "30588fe7-8885-4c81-93a2-d4f9c10d655e"
          },
          "ownerSystemId": {
            "type": "string",
            "example": "corporate-los"
          },
          "channelId": {
            "type": "string",
            "example": "infinity"
          }
        }
      },
      "UpdateDocumentResponse": {
        "type": "object",
        "description": "Update document response.",
        "properties": {
          "documentId": {
            "type": "string",
            "example": "30588fe7-8885-4c81-93a2-d4f9c10d655e"
          },
          "ownerSystemId": {
            "type": "string",
            "example": "corporate-los"
          },
          "channelId": {
            "type": "string",
            "example": "infinity"
          }
        }
      },
      "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."
          }
        }
      },
      "DocumentUpdate": {
        "type": "object",
        "required": [
          "updateDetails"
        ],
        "properties": {
          "updateDetails": {
            "$ref": "#/components/schemas/DocumentUpdateDetails"
          }
        }
      },
      "DocumentUpdateDetails": {
        "type": "object",
        "required": [
          "documentId",
          "action",
          "newOwnerSystemId",
          "newDocumentGroup",
          "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"
            }
          },
          "action": {
            "type": "string",
            "description": "The action key. Currently supported actions are DELIVERY, ADD_METADATA and UPDATE_METADATA.",
            "example": "DELIVERY"
          },
          "documentId": {
            "type": "string",
            "description": "Document Id.",
            "example": "30588fe7-8885-4c81-93a2-d4f9c10d655e"
          },
          "newOwnerSystemId": {
            "type": "string",
            "description": "Update this document with the new ownerSystemId. This input is requited for DELIVERY action only.",
            "example": "party"
          },
          "newDocumentGroup": {
            "type": "string",
            "description": "Update the document with the newDocumentGroup so you can access it after the delivery action is completed. This input is requited for DELIVERY action only.",
            "example": "journey-ownerSystemId-journeyID"
          }
        }
      },
      "SearchDocumentMetadata": {
        "description": "document metadata object",
        "properties": {
          "documentId": {
            "type": "string",
            "example": "30588fe7-8885-4c81-93a2-d4f9c10d655e"
          },
          "fileMetadata": {
            "description": "The file metadata is the file details such as name and size.",
            "type": "object",
            "example": {
              "fileName": "sling.PNG",
              "fileSize": 43522
            }
          },
          "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",
            "fileMetadata": {
              "fileName": "efs.pdf",
              "fileSize": 43522
            },
            "searchMetadata": {
              "attachmentType": "passport",
              "documentType": "attachment",
              "ownerId": "john.smith",
              "transactionId": "ABCDE"
            }
          },
          {
            "documentId": "24ef8b5a-b991-4a3c-bc6a-d089589ec284",
            "fileMetadata": {
              "fileName": "test.pdf",
              "fileSize": 123522
            },
            "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",
          "channelId",
          "fileName",
          "mimeType",
          "fileSize",
          "filePath",
          "searchMetadata",
          "documentGroup",
          "createdDate",
          "createdBy"
        ],
        "properties": {
          "documentId": {
            "type": "string",
            "example": "30588fe7-8885-4c81-93a2-d4f9c10d655e"
          },
          "ownerSystemId": {
            "description": "Owner System ID (Fabric Application ID)",
            "type": "string",
            "example": "corporate-los"
          },
          "channelId": {
            "description": "The document channel id. Different channels could potentially have different behaviours.",
            "type": "string",
            "example": "infinity"
          },
          "fileName": {
            "description": "File name",
            "type": "string",
            "example": "passport.jpg"
          },
          "mimeType": {
            "description": "File mime type",
            "type": "string",
            "example": "text/plain"
          },
          "fileSize": {
            "description": "File size in bytes.",
            "type": "integer",
            "format": "int64",
            "example": 1020
          },
          "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"
            }
          },
          "documentGroup": {
            "description": "Document group (Journey ID can be the value of the document group in the format of journey-ownerSystemId-journeyID)",
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "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": "corporate-los"
          },
          "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": "30588fe7-8885-4c81-93a2-d4f9c10d655e"
          },
          "ownerSystemId": {
            "type": "string",
            "example": "corporate-los"
          },
          "channelId": {
            "type": "string",
            "example": "infinity"
          }
        }
      },
      "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"
        }
      }
    }
  }
}