{
  "loglevel": "trace",
  "servicename": "azcosmosdb",
  "routes": [
    {
      "route": "/images",
      "type": "static",
      "configured": true,
      "routeclass": "./images",
      "description": "app specific images are served from the directory ./images under "
    },
    {
      "route": "/azcosmosdb/v1/databases",
      "type": "get",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "getAzcdbV1Databases",
      "description": "get databases",
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases"
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases",
      "type": "post",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "postAzcdbV1Databases",
      "description": "Create database by the name. The name has to be unique",
      "bodyschema": {
        "required": [
          "id"
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "id or name has to be unique. hierarchy is database->containers->items(collection)"
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases",
          "payload": {
            "id": "training"
          }
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database",
      "type": "get",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "getAzcdbV1DatabasesDatabase",
      "description": "get information about the database",
      "paramschema": {
        "type": "object",
        "required": [
          "database"
        ],
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training"
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database",
      "type": "delete",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "deleteAzcdbV1DatabasesDatabase",
      "description": "delete a specific databse",
      "paramschema": {
        "type": "object",
        "required": [
          "database"
        ],
        "properties": {
          "database": {
            "description": "database id",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training"
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers",
      "type": "get",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "getAzcdbV1DatabasesDatabaseContainers",
      "description": "get containers in a database",
      "paramschema": {
        "type": "object",
        "required": [
          "database"
        ],
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers"
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers",
      "type": "post",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "postAzcdbV1DatabasesDatabaseContainers",
      "description": "create containers in a database",
      "paramschema": {
        "type": "object",
        "required": [
          "database"
        ],
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          }
        }
      },
      "bodyschema": {
        "required": [
          "containerid",
          "partitionkey"
        ],
        "type": "object",
        "properties": {
          "containerid": {
            "type": "string",
            "description": "container idhierarchy is database->containers->items(collection)"
          },
          "partitionkey": {
            "type": "string",
            "description": "partitionkey should be in all the documents and even distribution of the keys makes it more efficient. It's the field by which documents are colocated, indexed etc."
          },
          "throughput": {
            "type": "integer",
            "description": "optional throughput value. Default is 400RU but you can be as high 10,000",
            "minimum": 400,
            "maximum": 10000
          },
          "uniquekeys": {
            "type": "array",
            "description": "array of key unique key objects. Similar to uniqness constraint in sql",
            "items": {
              "type": "object",
              "description": "arry of objects that contain the actual path components. The combination of the path strings should be unique within the container",
              "properties": {
                "paths": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "description": " a path string with / as the separator"
                  }
                }
              }
            }
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers",
          "payload": {
            "containerid": "tc",
            "partitionkey": "/partitionKey",
            "throughput": 400
          }
        },
        {
          "param": "/azcosmosdb/v1/databases/training/containers",
          "payload": {
            "containerid": "tc",
            "partitionkey": "/partitionKey",
            "throughput": 400,
            "uniquekeys": [
              {
                "paths": [
                  "/ssn"
                ]
              },
              {
                "paths": [
                  "/address/street",
                  "/address/city",
                  "/address/state",
                  "/address/zipCode"
                ]
              }
            ]
          }
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers/:container",
      "type": "get",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "getAzcdbV1DatabasesDatabaseContainersContainer",
      "description": "get container details in a database",
      "paramschema": {
        "type": "object",
        "required": [
          "database",
          "container"
        ],
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "container": {
            "description": "name of the container",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc"
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers/:container",
      "type": "delete",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "deleteAzcdbV1DatabasesDatabaseContainersContainer",
      "description": "delete container from a database",
      "paramschema": {
        "type": "object",
        "required": [
          "database",
          "container"
        ],
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "container": {
            "description": "name of the container",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc"
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers/:container/documents",
      "type": "get",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "GetDocuments",
      "description": "get documents in a container in a database",
      "paramschema": {
        "type": "object",
        "required": [
          "database",
          "container"
        ],
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "container": {
            "description": "name of the container",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/documents"
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers/:container/documents",
      "type": "post",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "CreateDocument",
      "description": "create containers in a database",
      "paramschema": {
        "type": "object",
        "required": [
          "database",
          "container"
        ],
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "container": {
            "description": "name of the container",
            "type": "string"
          },
          "failifexists": {
            "type": "boolean",
            "description": "create fails if this is set. Default (not set) behavior is to update if doc with same id exists"
          }
        }
      },
      "bodyschema": {
        "anyOf": [
          {
            "required": [
              "id",
              "type"
            ]
          },
          {
            "required": [
              "documents"
            ]
          },
          {
            "required": [
              "file"
            ]
          }
        ],
        "type": "object",
        "properties": {
          "file": {
            "type": "string",
            "description": "file path either absolute or releative to the app working directory"
          },
          "documents": {
            "type": "array",
            "description": "array of documents to be loaded",
            "items": {
              "type": "object",
              "required": [
                "id",
                "type"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "description": "type that groups documents. This is similar to tables in database schema. In general sense same type objects are expected to have same fields and follow similar symantics"
                },
                "type": {
                  "type": "string",
                  "description": "type that groups documents. This is similar to tables in database schema. In general sense same type objects are expected to have same fields and follow similar symantics"
                }
              }
            }
          },
          "id": {
            "type": "string",
            "description": "type that groups documents. This is similar to tables in database schema. In general sense same type objects are expected to have same fields and follow similar symantics"
          },
          "type": {
            "type": "string",
            "description": "type that groups documents. This is similar to tables in database schema. In general sense same type objects are expected to have same fields and follow similar symantics"
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/documents",
          "payload": {
            "id": "1",
            "type": "user",
            "email": "john.doe@acmecompany.com",
            "partitionKey": "john.doe@acmecompany.com",
            "firstname": "John",
            "lastname": "Doe",
            "role": "trainee"
          }
        },
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/documents",
          "payload": {
            "documents": [
              {
                "id": "201",
                "type": "user",
                "email": "john.doe201@acmecompany.com",
                "partitionKey": "john.doe201@acmecompany.com",
                "firstname": "John",
                "lastname": "Doe201",
                "role": "trainee"
              },
              {
                "id": "202",
                "type": "user",
                "email": "john.doe202@acmecompany.com",
                "partitionKey": "john.doe202@acmecompany.com",
                "firstname": "John",
                "lastname": "Doe202",
                "role": "training manager"
              }
            ]
          }
        },
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/documents?failifexists",
          "payload": {
            "file": "./trainingdata.json"
          }
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers/:container/documents/:documentid",
      "type": "get",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "GetDocument",
      "description": "get document details from given id",
      "paramschema": {
        "type": "object",
        "required": [
          "database",
          "container",
          "documentid"
        ],
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "container": {
            "description": "name of the container",
            "type": "string"
          },
          "documentid": {
            "description": "id of the container",
            "type": [
              "string",
              "integer"
            ]
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/documents/1"
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers/:container/documents/:documentid",
      "type": "put",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "UpdateDocument",
      "description": "create containers in a database. Note the id and partitionkey can't be changed for update",
      "paramschema": {
        "type": "object",
        "required": [
          "database",
          "container",
          "documentid"
        ],
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "container": {
            "description": "name of the container",
            "type": "string"
          },
          "documentid": {
            "description": "id of the container",
            "type": [
              "string",
              "integer"
            ]
          }
        }
      },
      "bodyschema": {
        "anyOf": [
          {
            "required": [
              "type"
            ]
          }
        ],
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "description": "type that groups documents. This is similar to tables in database schema. In general sense same type objects are expected to have same fields and follow similar symantics"
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/documents/1",
          "payload": {
            "firstname": "John",
            "lastname": "Doe",
            "phone": "1-621-407-2526 x25052",
            "email": "john.doe765@acmeexample.com",
            "key": "Ara.Ondricka7@acmeexample.com94108",
            "type": "user",
            "role": "sales manager trainee"
          }
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers/:container/documents/:documentid",
      "type": "delete",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "DeleteDocument",
      "description": "delete document details from given id",
      "paramschema": {
        "type": "object",
        "required": [
          "database",
          "container",
          "documentid"
        ],
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "container": {
            "description": "name of the container",
            "type": "string"
          },
          "documentid": {
            "description": "id of the container",
            "type": [
              "string",
              "integer"
            ]
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/documents/1"
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers/:container/query",
      "type": "post",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "QueryContainer",
      "description": "JSON query against the container",
      "bodyschema": {
        "description": "The query which constructs sql query from this",
        "type": "object",
        "required": [
          "select",
          "from"
        ],
        "dependecies": {
          "offset": [
            "limit"
          ]
        },
        "properties": {
          "select": {
            "type": "string",
            "description": "comma separated list of variables. dot notaion for navigating the fields"
          },
          "where": {
            "description": "where condition caluse can be expression that involves varous variables and properties",
            "type": "string"
          },
          "orderby": {
            "description": "order by it can be varible.property expression similar to where clause",
            "type": "string"
          },
          "groupby": {
            "description": "groupby",
            "type": "string"
          },
          "offset": {
            "type": "integer",
            "description": "0 default offset"
          },
          "limit": {
            "type": "integer",
            "description": "how many documents to retrieve"
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/query",
          "payload": {
            "select": "*",
            "from": "c",
            "orderby": "c.id"
          }
        },
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/query",
          "payload": {
            "select": "*",
            "from": "c",
            "where": "c.type='trainingdoc' and c.tstatus = 'instore pass'",
            "orderby": "c.id"
          }
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers/:container/execstatements",
      "type": "post",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "ExecStatements",
      "description": "execute sql query statements against the container",
      "bodyschema": {
        "description": "This executes sql query statement as it is",
        "type": "object",
        "required": [
          "statement"
        ],
        "properties": {
          "statement": {
            "type": "string",
            "description": "raw sql query (single) to be sent to cosmosdb"
          },
          "chunk": {
            "description": "chunk the query by adding offset and limit and fetching in chunks",
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/execstatements",
          "payload": {
            "statement": "select * from c"
          }
        },
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/statements",
          "payload": {
            "statement": "select * from c where c.type='trainingdoc' and c.tstatus = 'instore pass' order by c.id"
          }
        },
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/execstatements",
          "payload": {
            "statement": "select * from c",
            "chunk": 200
          }
        },
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/statements",
          "payload": {
            "statement": "select * from c where c.type='trainingdoc' and c.tstatus = 'instore pass' order by c.id",
            "chunk": 200
          }
        }

      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers/:container/storedprocs",
      "type": "get",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "GetSPs",
      "description": "get storeprocs in a container in a database",
      "paramschema": {
        "type": "object",
        "required": [
          "database",
          "container"
        ],
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "container": {
            "description": "name of the container",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/storedprocs"
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers/:container/storedprocs",
      "type": "post",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "CreateSP",
      "description": "create storedproc, for syntax and details refer to https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-write-stored-procedures-triggers-udfs",
      "paramschema": {
        "type": "object",
        "required": [
          "database",
          "container"
        ],
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "container": {
            "description": "name of the container",
            "type": "string"
          }
        }
      },
      "bodyschema": {
        "description": "javascript based stored proc body and id",
        "type": "object",
        "oneOf": [
          {
            "required": [
              "sprocid",
              "sprocbody",
              "sprocfunc"
            ]
          },
          {
            "required": [
              "sprocid",
              "sprocfile",
              "sprocfunc"
            ]
          }
        ],
        "properties": {
          "sprocid": {
            "type": "string",
            "description": "stored procedure id"
          },
          "sprocbody": {
            "description": "body of the procedure. ",
            "type": "string"
          },
          "sprocfile": {
            "description": "file containing the code for sproc ",
            "type": "string"
          },
          "sprocfunc": {
            "type": "string",
            "description": "name of the exported function - exports.funcname=function(params){body;} - that has the storedproc definition"
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/storedprocs",
          "payload": {
            "sprocid": "fetchdoc",
            "sprocfile": "sproc.js",
            "sprocfunc": "fetchdoc"
          }
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers/:container/storedprocs/:sprocid",
      "type": "get",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "GetSP",
      "description": "get specific storeproc identified by sprocid in a container in a database",
      "paramschema": {
        "type": "object",
        "required": [
          "database",
          "container",
          "sprocid"
        ],
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "container": {
            "description": "name of the container",
            "type": "string"
          },
          "sprocid": {
            "description": "name of the storedproc",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/storedprocs/fetchdoc"
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers/:container/storedprocs/:sprocid",
      "type": "put",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "ExecSP",
      "description": "get specific storeproc identified by sprocid in a container in a database",
      "paramschema": {
        "type": "object",
        "required": [
          "database",
          "container",
          "sprocid"
        ],
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "container": {
            "description": "name of the container",
            "type": "string"
          },
          "sprocid": {
            "description": "name of the storedproc",
            "type": "string"
          }
        }
      },
      "bodyschema": {
        "type": "object",
        "description": "necessary for execution includes partitionkey and parameters",
        "required": [
          "partitionkey"
        ],
        "properties": {
          "partitionkey": {
            "type": "string",
            "description": "partition key is required to execute storedprocedure. This makes fetching or querying a problem unless within the document"
          },
          "params": {
            "description": "whatever parameters to be passed to the storedproc for execution "
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/storedprocs/fetchdoc",
          "payload": {
            "partitionkey": "Berenice.Funk58@acmeexample.com",
            "params": {
              "id": "1"
            }
          }
        },
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/storedprocs/fetchdoc",
          "payload": {
            "partitionkey": "Margaretta_Gusikowski@acmeexample.com",
            "params": {
              "id": "2"
            }
          }
        }
      ]
    },
    {
      "route": "/azcosmosdb/v1/databases/:database/containers/:container/storedprocs/:sprocid",
      "type": "delete",
      "configured": true,
      "routeclass": "azcosmosdb.js",
      "routefunction": "DeleteSP",
      "description": "delete specific storeproc identified by sprocid in a container in a database",
      "paramschema": {
        "type": "object",
        "required": [
          "database",
          "container",
          "sprocid"
        ],
        "properties": {
          "database": {
            "description": "name of the database",
            "type": "string"
          },
          "container": {
            "description": "name of the container",
            "type": "string"
          },
          "sprocid": {
            "description": "name of the storedproc",
            "type": "string"
          }
        }
      },
      "examples": [
        {
          "param": "/azcosmosdb/v1/databases/training/containers/tc/storedprocs/fetchdoc"
        }
      ]
    }
  ]
}