{
  "$comment": "Based on https://github.wdf.sap.corp/xs2/approuter.js/blob/master/lib/configuration/schemas/xs-app-schema.json",
  "$id": "https://json.schemastore.org/xs-app.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "sourceSchema": {
      "type": ["string", "object"],
      "minLength": 1,
      "format": "regex",
      "additionalProperties": false,
      "properties": {
        "path": {
          "type": "string",
          "minLength": 1,
          "format": "regex"
        },
        "matchCase": {
          "type": "boolean"
        }
      },
      "required": ["path"]
    },
    "scopesSchema": {
      "type": ["string", "array", "object"],
      "minProperties": 1,
      "additionalProperties": false,
      "properties": {
        "GET": {
          "$ref": "#/definitions/scopeTemplate"
        },
        "POST": {
          "$ref": "#/definitions/scopeTemplate"
        },
        "HEAD": {
          "$ref": "#/definitions/scopeTemplate"
        },
        "PUT": {
          "$ref": "#/definitions/scopeTemplate"
        },
        "DELETE": {
          "$ref": "#/definitions/scopeTemplate"
        },
        "TRACE": {
          "$ref": "#/definitions/scopeTemplate"
        },
        "PATCH": {
          "$ref": "#/definitions/scopeTemplate"
        },
        "OPTIONS": {
          "$ref": "#/definitions/scopeTemplate"
        },
        "CONNECT": {
          "$ref": "#/definitions/scopeTemplate"
        },
        "default": {
          "$ref": "#/definitions/scopeTemplate"
        }
      },
      "minLength": 1,
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "scopeTemplate": {
      "$id": "scopeTemplate",
      "type": ["string", "array"],
      "minLength": 1,
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 1
      }
    }
  },
  "description": "Application Router Configuration Schema",
  "properties": {
    "welcomeFile": {
      "type": "string",
      "minLength": 1
    },
    "authenticationMethod": {
      "type": "string",
      "enum": ["none", "route"]
    },
    "sessionTimeout": {
      "type": "integer",
      "minimum": 1
    },
    "pluginMetadataEndpoint": {
      "type": "string",
      "minLength": 1,
      "format": "relative-uri"
    },
    "routes": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "format": "route-rules",
        "properties": {
          "source": {
            "$ref": "#/definitions/sourceSchema"
          },
          "httpMethods": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "enum": [
                "DELETE",
                "GET",
                "HEAD",
                "OPTIONS",
                "POST",
                "PUT",
                "TRACE",
                "PATCH"
              ]
            }
          },
          "target": {
            "type": "string",
            "minLength": 1,
            "format": "relative-uri"
          },
          "destination": {
            "type": "string",
            "minLength": 1
          },
          "localDir": {
            "type": "string",
            "minLength": 1
          },
          "csrfProtection": {
            "type": "boolean"
          },
          "service": {
            "type": "string"
          },
          "endpoint": {
            "type": "string"
          },
          "authenticationType": {
            "type": "string",
            "enum": ["xsuaa", "basic", "none"]
          },
          "identityProvider": {
            "type": "string",
            "minLength": 1
          },
          "scope": {
            "$ref": "#/definitions/scopesSchema"
          },
          "replace": {
            "type": "object",
            "required": ["pathSuffixes"],
            "additionalProperties": false,
            "properties": {
              "pathSuffixes": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1,
                  "format": "relative-uri"
                }
              },
              "vars": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "services": {
                "type": "object"
              }
            }
          },
          "cacheControl": {
            "type": "string",
            "minLength": 1,
            "format": "valid-header-value"
          }
        },
        "required": ["source"]
      }
    },
    "destinations": {
      "type": "object",
      "format": "destinations-rules",
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "logoutPath": {
            "type": "string",
            "minLength": 1,
            "format": "relative-uri"
          },
          "logoutMethod": {
            "type": "string",
            "enum": ["PUT", "POST", "GET"]
          }
        }
      }
    },
    "services": {
      "type": "object",
      "format": "services-rules",
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "endpoint": {
            "type": "string",
            "minLength": 1
          },
          "logoutPath": {
            "type": "string",
            "minLength": 1,
            "format": "relative-uri"
          },
          "logoutMethod": {
            "type": "string",
            "enum": ["PUT", "POST", "GET"]
          }
        }
      }
    },
    "logout": {
      "type": "object",
      "additionalProperties": false,
      "format": "logout-rules",
      "properties": {
        "logoutEndpoint": {
          "type": "string",
          "minLength": 1,
          "format": "relative-uri"
        },
        "logoutPage": {
          "type": "string",
          "minLength": 1,
          "format": "uri"
        }
      }
    },
    "login": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "callbackEndpoint": {
          "type": "string",
          "minLength": 1,
          "format": "relative-uri"
        }
      },
      "required": ["callbackEndpoint"]
    },
    "whitelistService": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "endpoint": {
          "type": "string",
          "minLength": 1,
          "format": "relative-uri"
        }
      },
      "required": ["endpoint"]
    },
    "compression": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "minSize": {
          "type": "integer",
          "minimum": 1
        }
      }
    },
    "websockets": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "enabled": {
          "type": "boolean"
        }
      },
      "required": ["enabled"]
    },
    "errorPage": {
      "type": "array",
      "additionalProperties": false,
      "items": {
        "type": "object",
        "required": ["status", "file"],
        "properties": {
          "status": {
            "type": ["integer", "array"],
            "minimum": 1,
            "minItems": 1,
            "uniqueItems": true,
            "items": {
              "type": "integer",
              "minimum": 1
            }
          },
          "file": {
            "type": "string",
            "minLength": 1,
            "format": "local-file"
          }
        }
      }
    }
  },
  "title": "com.sap.xsapp.schema_8.2",
  "type": "object"
}
