{
  "openapi": "3.0.3",
  "paths": {
    "/files": {
      "get": {
        "tags": [
          "Files"
        ],
        "summary": "List file",
        "parameters": [
          {
            "name": "includeTotal",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "pageToken",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-org-id",
            "in": "header",
            "required": false
          }
        ],
        "deprecated": false,
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/File"
                      }
                    },
                    "nextPageToken": {
                      "type": "string"
                    },
                    "totalCount": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid search provided",
            "content": {}
          },
          "401": {
            "description": "Missing or invalid authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Invalid permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Files"
        ],
        "summary": "Create a file",
        "parameters": [],
        "deprecated": false,
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "ref": {
                    "type": "object",
                    "properties": {
                      "namespace": {
                        "type": "string",
                        "const": "native-object"
                      },
                      "typeId": {
                        "type": "string"
                      },
                      "instanceId": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "namespace",
                      "typeId",
                      "instanceId"
                    ],
                    "additionalProperties": false
                  },
                  "meta": {
                    "allOf": [
                      {
                        "type": "object",
                        "properties": {
                          "contentType": {
                            "type": "string"
                          }
                        },
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "propertyNames": {
                          "type": "string"
                        },
                        "additionalProperties": {}
                      }
                    ]
                  }
                },
                "required": [
                  "ref"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "uploadUrl": {
                      "type": "string",
                      "format": "uri"
                    },
                    "resumable": {
                      "type": "object",
                      "properties": {
                        "protocol": {
                          "type": "string",
                          "const": "contextual-blocks-v1"
                        },
                        "maxBytes": {
                          "type": "number"
                        },
                        "chunkSize": {
                          "type": "number"
                        }
                      },
                      "required": [
                        "protocol",
                        "maxBytes",
                        "chunkSize"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "id",
                    "uploadUrl"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "400": {
            "description": "Invalid payload provided",
            "content": {}
          },
          "401": {
            "description": "Missing or invalid authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Invalid permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/[\\$]page/files": {
      "post": {
        "tags": [
          "Files"
        ],
        "summary": "Page file",
        "parameters": [
          {
            "name": "x-org-id",
            "in": "header",
            "required": false
          }
        ],
        "deprecated": false,
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/$ListQuery"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/File"
                      }
                    },
                    "nextPageToken": {
                      "type": "string"
                    },
                    "totalCount": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "items"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid search provided",
            "content": {}
          },
          "401": {
            "description": "Missing or invalid authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Invalid permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/files/{id}": {
      "post": {
        "tags": [
          "Files"
        ],
        "summary": "Upload a file",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "deprecated": false,
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/File"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Invalid permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "File not found or already uploaded",
            "content": {}
          }
        }
      },
      "get": {
        "tags": [
          "Files"
        ],
        "summary": "Get file by id",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "deprecated": false,
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/File"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Invalid permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "File not found",
            "content": {}
          }
        }
      },
      "patch": {
        "tags": [
          "Files"
        ],
        "summary": "Patch file meta by id",
        "parameters": [
          {
            "name": "x-if-hash-match",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "deprecated": false,
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "path": {
                          "type": "string",
                          "allOf": [
                            {
                              "pattern": "^\\/meta\\/"
                            },
                            {
                              "pattern": "^\\/meta\\/(?!path|contentType|contentMD5|size)"
                            }
                          ]
                        },
                        "value": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "boolean"
                            },
                            {
                              "type": "number"
                            },
                            {
                              "type": "object",
                              "propertyNames": {
                                "type": "string"
                              },
                              "additionalProperties": {}
                            },
                            {
                              "type": "array",
                              "items": {}
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "op": {
                          "type": "string",
                          "const": "add"
                        }
                      },
                      "required": [
                        "path",
                        "value",
                        "op"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "path": {
                          "type": "string",
                          "allOf": [
                            {
                              "pattern": "^\\/meta\\/"
                            },
                            {
                              "pattern": "^\\/meta\\/(?!path|contentType|contentMD5|size)"
                            }
                          ]
                        },
                        "value": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "boolean"
                            },
                            {
                              "type": "number"
                            },
                            {
                              "type": "object",
                              "propertyNames": {
                                "type": "string"
                              },
                              "additionalProperties": {}
                            },
                            {
                              "type": "array",
                              "items": {}
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "op": {
                          "type": "string",
                          "const": "set"
                        }
                      },
                      "required": [
                        "path",
                        "value",
                        "op"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "path": {
                          "type": "string",
                          "allOf": [
                            {
                              "pattern": "^\\/meta\\/"
                            },
                            {
                              "pattern": "^\\/meta\\/(?!path|contentType|contentMD5|size)"
                            }
                          ]
                        },
                        "value": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "boolean"
                            },
                            {
                              "type": "number"
                            },
                            {
                              "type": "object",
                              "propertyNames": {
                                "type": "string"
                              },
                              "additionalProperties": {}
                            },
                            {
                              "type": "array",
                              "items": {}
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "op": {
                          "type": "string",
                          "const": "replace"
                        }
                      },
                      "required": [
                        "path",
                        "value",
                        "op"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "path": {
                          "type": "string",
                          "allOf": [
                            {
                              "pattern": "^\\/meta\\/"
                            },
                            {
                              "pattern": "^\\/meta\\/(?!path|contentType|contentMD5|size)"
                            }
                          ]
                        },
                        "value": {
                          "anyOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "boolean"
                            },
                            {
                              "type": "number"
                            },
                            {
                              "type": "object",
                              "propertyNames": {
                                "type": "string"
                              },
                              "additionalProperties": {}
                            },
                            {
                              "type": "array",
                              "items": {}
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "op": {
                          "type": "string",
                          "const": "incr"
                        }
                      },
                      "required": [
                        "path",
                        "value",
                        "op"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "op": {
                          "type": "string",
                          "const": "remove"
                        },
                        "path": {
                          "type": "string",
                          "allOf": [
                            {
                              "pattern": "^\\/meta\\/"
                            },
                            {
                              "pattern": "^\\/meta\\/(?!path|contentType|contentMD5|size)"
                            }
                          ]
                        }
                      },
                      "required": [
                        "op",
                        "path"
                      ],
                      "additionalProperties": false
                    }
                  ],
                  "type": "object"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "File meta updated successfully",
            "content": {}
          },
          "401": {
            "description": "Missing or invalid authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Invalid permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "File not found",
            "content": {}
          }
        }
      },
      "delete": {
        "tags": [
          "Files"
        ],
        "summary": "Delete file by id",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "deprecated": false,
        "responses": {
          "204": {
            "description": "File deleted successfully",
            "content": {}
          },
          "401": {
            "description": "Missing or invalid authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Invalid permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "File not found",
            "content": {}
          }
        }
      }
    },
    "/files/{id}/content": {
      "get": {
        "tags": [
          "Files"
        ],
        "summary": "Get file by id",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "deprecated": false,
        "responses": {
          "200": {
            "description": "Contents of the file",
            "content": {}
          },
          "401": {
            "description": "Missing or invalid authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Invalid permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "File not found",
            "content": {}
          }
        }
      }
    },
    "/files/{id}/uploads": {
      "post": {
        "tags": [
          "Files"
        ],
        "summary": "Create or resume a chunked file upload",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true
          }
        ],
        "deprecated": false,
        "responses": {
          "401": {
            "description": "Missing or invalid authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Invalid permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/files/{id}/uploads/{sessionId}": {
      "get": {
        "tags": [
          "Files"
        ],
        "summary": "Get completed chunks and upload status",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true
          },
          {
            "name": "id",
            "in": "path",
            "required": true
          }
        ],
        "deprecated": false,
        "responses": {
          "401": {
            "description": "Missing or invalid authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Invalid permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Files"
        ],
        "summary": "Discard an unfinished upload session",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true
          },
          {
            "name": "id",
            "in": "path",
            "required": true
          }
        ],
        "deprecated": false,
        "responses": {
          "401": {
            "description": "Missing or invalid authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Invalid permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/files/{id}/uploads/{sessionId}/chunks/{index}": {
      "put": {
        "tags": [
          "Files"
        ],
        "summary": "Stage one verified upload chunk",
        "parameters": [
          {
            "name": "index",
            "in": "path",
            "required": true
          },
          {
            "name": "sessionId",
            "in": "path",
            "required": true
          },
          {
            "name": "id",
            "in": "path",
            "required": true
          }
        ],
        "deprecated": false,
        "responses": {
          "401": {
            "description": "Missing or invalid authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Invalid permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/files/{id}/uploads/{sessionId}/complete": {
      "post": {
        "tags": [
          "Files"
        ],
        "summary": "Commit a complete upload and link its attachment",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true
          },
          {
            "name": "id",
            "in": "path",
            "required": true
          }
        ],
        "deprecated": false,
        "responses": {
          "401": {
            "description": "Missing or invalid authorization header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Invalid permissions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/$ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "jwt": []
    }
  ],
  "components": {
    "schemas": {
      "$ListQuery": {
        "type": "object",
        "properties": {
          "pageToken": {
            "type": "string",
            "minLength": 1
          },
          "orderBy": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          },
          "fields": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          },
          "pageSize": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "includeTotal": {
            "type": "boolean"
          },
          "filterMode": {
            "anyOf": [
              {
                "type": "string",
                "const": "AND"
              },
              {
                "type": "string",
                "const": "OR"
              }
            ]
          }
        },
        "additionalProperties": false
      },
      "$ErrorResponse": {
        "type": "object",
        "properties": {
          "code": {
            "type": [
              "string",
              "number"
            ]
          },
          "message": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {}
          }
        },
        "required": [
          "code",
          "message"
        ],
        "additionalProperties": false
      },
      "File": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "filename": {
            "type": "string"
          },
          "meta": {
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "path": {
                    "type": "string"
                  },
                  "contentType": {
                    "type": "string"
                  },
                  "contentMD5": {
                    "type": "string"
                  },
                  "size": {
                    "type": "number"
                  }
                },
                "required": [
                  "path",
                  "contentType",
                  "size"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "propertyNames": {
                  "type": "string"
                },
                "additionalProperties": {}
              }
            ]
          },
          "_metaData": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "createdAt": {
                "type": "string",
                "pattern": "^(?:\\d+(?:\\.\\d+?)?|(?:\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?Z))$",
                "description": "An ISO 8601 date time string",
                "format": "date-time"
              },
              "updatedAt": {
                "type": "string",
                "pattern": "^(?:\\d+(?:\\.\\d+?)?|(?:\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?Z))$",
                "description": "An ISO 8601 date time string",
                "format": "date-time"
              },
              "ref": {
                "type": "object",
                "properties": {
                  "namespace": {
                    "type": "string",
                    "const": "native-object"
                  },
                  "typeId": {
                    "type": "string"
                  },
                  "instanceId": {
                    "type": "string"
                  }
                },
                "required": [
                  "namespace",
                  "typeId",
                  "instanceId"
                ],
                "additionalProperties": false
              }
            },
            "required": [
              "id",
              "createdAt",
              "ref"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "id",
          "filename",
          "meta",
          "_metaData"
        ],
        "additionalProperties": false
      }
    },
    "securitySchemes": {
      "jwt": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    }
  },
  "info": {
    "title": "Files Api",
    "description": " ",
    "version": "1.6.3"
  },
  "servers": [
    {
      "url": "/api/v1"
    }
  ]
}
