{
  "openapi": "3.0.1",
  "servers": [{ "url": "https://apis.<domain>" }],
  "info": { "title": "connhex-remote-init", "version": "1.5.0" },
  "paths": {
    "/iot/edge/configs": {
      "post": {
        "summary": "Adds new config",
        "description": "Adds new config to the list of config owned by user identified using\nthe provided access token.\n\nRequired Permission:\n\n - Resource: ```core:configs```\n\n - Action: ```core:configs:create```",
        "tags": ["Configs"],
        "security": [{ "chx_auth_session": [] }, { "bearer": [] }],
        "requestBody": { "$ref": "#/components/requestBodies/ConfigCreateReq" },
        "responses": {
          "201": { "$ref": "#/components/responses/ConfigCreateRes" },
          "400": { "description": "Bad request." },
          "401": { "description": "Unauthorized." },
          "415": { "description": "Missing or unsupported content type." },
          "500": { "$ref": "#/components/responses/ServiceError" }
        }
      }
    },
    "/iot/edge/configs/{configId}": {
      "get": {
        "summary": "Retrieves config info by id",
        "description": "Retrieves config info by id.\n\nRequired Permission:\n\n - Resource: ```core:configs:{id}```\n\n - Action: ```core:configs:get```",
        "tags": ["Configs"],
        "security": [{ "chx_auth_session": [] }, { "bearer": [] }],
        "parameters": [{ "$ref": "#/components/parameters/ConfigId" }],
        "responses": {
          "200": { "$ref": "#/components/responses/ConfigRes" },
          "401": { "description": "Unauthorized." },
          "404": { "description": "Config not found." },
          "500": { "$ref": "#/components/responses/ServiceError" }
        }
      },
      "put": {
        "summary": "Updates config info",
        "description": "Update is performed by replacing the current resource data with values\nprovided in a request payload. Note that the owner, ID, init ID,\ninit key, Connhex Thing ID and key cannot be changed.\n\nRequired Permission:\n\n - Resource: ```core:configs:{id}```\n\n - Action: ```core:configs:update```",
        "security": [{ "chx_auth_session": [] }, { "bearer": [] }],
        "tags": ["Configs"],
        "parameters": [{ "$ref": "#/components/parameters/ConfigId" }],
        "requestBody": { "$ref": "#/components/requestBodies/ConfigUpdateReq" },
        "responses": {
          "200": { "description": "Config updated." },
          "400": { "description": "Bad request." },
          "401": { "description": "Unauthorized." },
          "404": { "description": "Config not found." },
          "415": { "description": "Missing or unsupported content type." },
          "500": { "$ref": "#/components/responses/ServiceError" }
        }
      }
    },
    "/iot/edge/init/{initId}": {
      "get": {
        "summary": "Retrieves config by init id",
        "description": "Retrieves a configuration with given init ID and init key.\n",
        "tags": ["Configs"],
        "security": [{ "thingKey": [] }],
        "parameters": [{ "$ref": "#/components/parameters/InitId" }],
        "responses": {
          "200": { "$ref": "#/components/responses/BootstrapConfigRes" },
          "400": { "description": "Bad request." },
          "401": { "description": "Unauthorized." },
          "404": { "description": "Config not found." },
          "500": { "$ref": "#/components/responses/ServiceError" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "State": { "type": "integer", "enum": [0, 1] },
      "Config": {
        "type": "object",
        "properties": {
          "connhex_id": {
            "type": "string",
            "format": "uuid",
            "description": "Corresponding Connhex Thing ID."
          },
          "connhex_key": {
            "type": "string",
            "format": "uuid",
            "description": "Corresponding Connhex Thing key."
          },
          "connhex_channels": {
            "type": "array",
            "minItems": 0,
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid",
                  "description": "Channel unique identifier."
                },
                "name": {
                  "type": "string",
                  "description": "Name of the Channel."
                },
                "metadata": {
                  "type": "object",
                  "description": "Custom metadata related to the Channel."
                }
              }
            }
          },
          "init_id": {
            "type": "string",
            "description": "MAC address or other identifier."
          },
          "init_key": { "type": "string", "description": "init key." },
          "content": {
            "type": "string",
            "description": "Free-form custom configuration."
          },
          "state": { "$ref": "#/components/schemas/State" }
        },
        "required": ["init_id", "init_key"]
      },
      "ConfigList": {
        "type": "object",
        "properties": {
          "total": {
            "type": "integer",
            "description": "Total number of results.",
            "minimum": 0
          },
          "offset": {
            "type": "integer",
            "description": "Number of items to skip during retrieval.",
            "minimum": 0,
            "default": 0
          },
          "limit": {
            "type": "integer",
            "description": "Size of the subset to retrieve.",
            "maximum": 100,
            "default": 10
          },
          "configs": {
            "type": "array",
            "minItems": 0,
            "uniqueItems": true,
            "items": { "$ref": "#/components/schemas/Config" }
          }
        },
        "required": ["Configs"]
      },
      "BootstrapConfig": {
        "type": "object",
        "properties": {
          "connhex_id": {
            "type": "string",
            "format": "uuid",
            "description": "Corresponding Connhex Thing ID."
          },
          "connhex_key": {
            "type": "string",
            "format": "uuid",
            "description": "Corresponding Connhex Thing key."
          },
          "connhex_channels": {
            "type": "array",
            "minItems": 0,
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid",
                  "description": "Channel unique identifier."
                },
                "name": {
                  "type": "string",
                  "description": "Name of the Channel."
                },
                "metadata": {
                  "type": "object",
                  "description": "Custom metadata related to the Channel."
                }
              }
            }
          },
          "content": {
            "type": "string",
            "description": "Free-form custom configuration."
          },
          "client_cert": {
            "type": "string",
            "description": "Client certificate."
          },
          "client_key": {
            "type": "string",
            "description": "Key for the client_cert."
          },
          "ca_cert": {
            "type": "string",
            "description": "Issuing CA certificate."
          }
        },
        "required": ["connhex_id", "connhex_key", "connhex_channels", "content"]
      }
    },
    "parameters": {
      "ConfigId": {
        "name": "configId",
        "description": "Unique Config identifier. It's the ID of the corresponding Thing.",
        "in": "path",
        "schema": { "type": "string", "format": "uuid" },
        "required": true
      },
      "InitId": {
        "name": "initId",
        "description": "Unique Config identifier provided by init entity.",
        "in": "path",
        "schema": { "type": "string" },
        "required": true
      },
      "Limit": {
        "name": "limit",
        "description": "Size of the subset to retrieve.",
        "in": "query",
        "schema": {
          "type": "integer",
          "default": 10,
          "maximum": 100,
          "minimum": 1
        },
        "required": false
      },
      "Offset": {
        "name": "offset",
        "description": "Number of items to skip during retrieval.",
        "in": "query",
        "schema": { "type": "integer", "default": 0, "minimum": 0 },
        "required": false
      },
      "State": {
        "name": "state",
        "description": "A state of items",
        "in": "query",
        "schema": { "$ref": "#/components/schemas/State" },
        "required": false
      },
      "Name": {
        "name": "name",
        "description": "Name of the config. Search by name is partial-match and case-insensitive.",
        "in": "query",
        "schema": { "type": "string" },
        "required": false
      }
    },
    "requestBodies": {
      "ConfigCreateReq": {
        "description": "JSON-formatted document describing the new config.",
        "required": true,
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "init_id": {
                  "type": "string",
                  "description": "MAC address or other indentifier."
                },
                "init_key": {
                  "type": "string",
                  "description": "init key."
                },
                "thing_id": {
                  "type": "string",
                  "description": "ID of the corresponding Connhex Thing."
                },
                "channels": {
                  "type": "array",
                  "minItems": 0,
                  "items": { "type": "string" }
                },
                "content": { "type": "string" }
              },
              "required": ["init_id", "init_key"]
            }
          }
        }
      },
      "ConfigUpdateReq": {
        "description": "JSON-formatted document describing the updated thing.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "content": { "type": "string" },
                "name": { "type": "string" }
              },
              "required": ["content", "name"]
            }
          }
        }
      },
      "ConfigCertUpdateReq": {
        "description": "JSON-formatted document describing the updated thing.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "client_cert": { "type": "string" },
                "client_key": { "type": "string" },
                "ca_cert": { "type": "string" }
              }
            }
          }
        }
      },
      "ConfigConnUpdateReq": {
        "description": "Array if IDs the thing is be connected to.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "channels": {
                  "type": "array",
                  "minItems": 0,
                  "items": { "type": "string" }
                }
              }
            }
          }
        }
      },
      "ConfigStateUpdateReq": {
        "description": "Update the state of the Config.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "state": { "$ref": "#/components/schemas/State" }
              }
            }
          }
        }
      }
    },
    "responses": {
      "ConfigCreateRes": {
        "description": "Config created.",
        "headers": {
          "Location": {
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string",
                  "description": "Created configuration's relative URL (i.e. /things/configs/{configId})."
                }
              }
            }
          }
        }
      },
      "ConfigListRes": {
        "description": "Data retrieved.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/ConfigList" }
          }
        }
      },
      "ConfigRes": {
        "description": "Data retrieved.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Config" }
          }
        }
      },
      "BootstrapConfigRes": {
        "description": "Data retrieved.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/BootstrapConfig" }
          }
        }
      },
      "ServiceError": { "description": "Unexpected server error." }
    },
    "securitySchemes": {
      "$ref": "../../../common.json#/components/securitySchemes"
    }
  },
  "security": [{ "chx_auth_session": [] }, { "bearer": [] }, { "thingKey": [] }]
}
