{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "API",
  "description": "API declaration",
  "type": "object",
  "definitions": {
    "jsonReference": {
      "type": "object",
      "required": [
        "$ref"
      ],
      "additionalProperties": false,
      "properties": {
        "$ref": {
          "type": "string"
        }
      }
    },
    "parameterArray": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#"
      }
    },
    "parameterTypes": {
      "type": "string",
      "enum": [
        "array",
        "boolean",
        "integer",
        "number",
        "string"
      ]
    },
    "responseTypes": {
      "type": "string",
      "enum": [
        "array",
        "boolean",
        "integer",
        "number",
        "string",
        "object"
      ]
    },
    "responsePropertyTypes": {
      "type": "string",
      "enum": [
        "array",
        "boolean",
        "integer",
        "number",
        "string"
      ]
    },
    "itemTypes": {
      "type": "string",
      "enum": [
        "boolean",
        "integer",
        "number",
        "string"
      ]
    },
    "parameter": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "description": "Parameter name"
        },
        "format": {
          "type": "string",
          "enum": [
            "json"
          ]
        },
        "type": {
          "$ref": "#/definitions/parameterTypes",
          "description": "Parameter type"
        },
        "items": {
          "type": "object",
          "properties": {
            "$ref": {
              "type": "string",
              "format": "uri-reference"
            },
            "type": {
              "$ref": "#/definitions/itemTypes"
            },
            "maximum": {
              "type": "number"
            },
            "minimum": {
              "type": "number"
            },
            "enum": {
              "type": "array",
              "minItems": 1,
              "_uniqueItems": true
            },
            "enumNames": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "minItems": 1,
              "_uniqueItems": true
            }
          },
          "oneOf": [
            {
              "required": [
                "type"
              ]
            },
            {
              "required": [
                "$ref"
              ]
            }
          ],
          "additionalProperties": false
        },
        "maxItems": {
          "type": "integer",
          "minimum": 0
        },
        "minItems": {
          "type": "integer",
          "minimum": 0,
          "default": 0
        },
        "maximum": {
          "type": "number"
        },
        "minimum": {
          "type": "number"
        },
        "$ref": {
          "type": "string",
          "format": "uri-reference"
        },
        "enum": {
          "type": "array",
          "minItems": 1,
          "_uniqueItems": true
        },
        "enumNames": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1,
          "_uniqueItems": true
        },
        "required": {
          "type": "boolean",
          "default": false
        },
        "maxLength": {
          "type": "integer",
          "minimum": 0
        },
        "minLength": {
          "type": "integer",
          "minimum": 0,
          "default": 0
        },
        "description": {
          "type": "string",
          "description": "Parameter description"
        },
        "deprecated_from_version": {
          "type": "string",
          "description": "Property deprecated from version"
        },
        "from_version": {
          "type": "string",
          "description": "Property implemented from version"
        }
      },
      "required": [
        "name",
        "type"
      ],
      "additionalProperties": false
    },
    "responseProperty": {
      "type": "object",
      "oneOf": [
        {
          "required": [
            "type"
          ]
        },
        {
          "required": [
            "$ref"
          ]
        }
      ],
      "properties": {
        "type": {
          "$ref": "#/definitions/responseTypes"
        },
        "description": {
          "type": "string"
        }
      }
    },
    "response": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string"
        },
        "deprecated_from_version": {
          "type": "string"
        },
        "from_version": {
          "type": "string"
        },
        "items": {
          "oneOf": [
            {
              "type": "array"
            },
            {
              "type": "object",
              "properties": {
                "$ref": {
                  "type": "string"
                }
              }
            }
          ]
        },
        "required": {
          "type": "array"
        },
        "title": {
          "type": "string"
        },
        "oneOf": {
          "type": "array"
        },
        "$ref": {
          "type": "string",
          "format": "uri-reference"
        },
        "properties": {
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z0-9_]+$": {
              "$ref": "#/definitions/responseProperty"
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "error": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "description": "Error name"
        },
        "code": {
          "type": "integer",
          "description": "Error code",
          "minimum": 0
        },
        "description": {
          "type": "string",
          "description": "Error description"
        },
        "deprecated_from_version": {
          "type": "string"
        },
        "from_version": {
          "type": "string"
        }
      },
      "required": [
        "name",
        "code",
        "description"
      ],
      "additionalProperties": false
    },
    "errors": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/error"
      },
      "description": "Possible errors"
    },
    "method": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "description": "Method name"
        },
        "description": {
          "type": "string",
          "description": "Method description"
        },
        "deprecated_from_version": {
          "type": "string"
        },
        "from_version": {
          "type": "string"
        },
        "access_token_type": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "open",
              "user",
              "group",
              "service"
            ],
            "description": "Access token type"
          },
          "description": "Input parameters for method"
        },
        "parameters": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/parameter"
          },
          "description": "Input parameters for method"
        },
        "responses": {
          "type": "object",
          "patternProperties": {
            "^([a-zA-Z0-9_]+)?[rR]esponse$": {
              "$ref": "#/definitions/response"
            }
          },
          "additionalProperties": true,
          "description": "References to response objects"
        },
        "emptyResponse": {
          "type": "boolean",
          "default": false
        },
        "errors": {
          "$ref": "#/definitions/errors"
        }
      },
      "required": [
        "name",
        "access_token_type",
        "responses"
      ],
      "additionalProperties": false
    }
  },
  "properties": {
    "errors": {
      "$ref": "#/definitions/errors"
    },
    "methods": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/method"
      }
    },
    "definitions": {
      "patternProperties": {
        "^([a-zA-Z0-9_]+)?[rR]esponse$": {
          "$ref": "#/definitions/response"
        }
      }
    },
    "$schema": {
      "type": "string",
      "format": "uri-reference"
    },
    "title": {
      "type": "string"
    }
  },
  "additionalProperties": false
}