{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://catalog.lintel.tools/schemas/schemastore/xs-app-json/latest.json",
  "title": "com.sap.xsapp.schema_8.2",
  "description": "Application Router Configuration Schema",
  "x-lintel": {
    "source": "https://www.schemastore.org/xs-app.json",
    "sourceSha256": "da858ca23ff31cad8c18e5fb5e708505888cb211de5d9147d14f82fe75b9918a",
    "fileMatch": [
      "xs-app.json"
    ],
    "parsers": [
      "json"
    ]
  },
  "type": "object",
  "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",
        "required": [
          "source"
        ],
        "format": "route-rules",
        "properties": {
          "source": {
            "$ref": "#/$defs/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",
              "ias",
              "none"
            ]
          },
          "identityProvider": {
            "type": "string",
            "minLength": 1
          },
          "scope": {
            "$ref": "#/$defs/scopesSchema"
          },
          "replace": {
            "type": "object",
            "required": [
              "pathSuffixes"
            ],
            "properties": {
              "pathSuffixes": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1,
                  "format": "relative-uri"
                }
              },
              "vars": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "services": {
                "type": "object"
              }
            },
            "additionalProperties": false
          },
          "cacheControl": {
            "type": "string",
            "minLength": 1,
            "format": "valid-header-value"
          }
        },
        "additionalProperties": false
      }
    },
    "destinations": {
      "type": "object",
      "format": "destinations-rules",
      "additionalProperties": {
        "type": "object",
        "properties": {
          "logoutPath": {
            "type": "string",
            "minLength": 1,
            "format": "relative-uri"
          },
          "logoutMethod": {
            "type": "string",
            "enum": [
              "PUT",
              "POST",
              "GET"
            ]
          }
        },
        "additionalProperties": false
      }
    },
    "services": {
      "type": "object",
      "format": "services-rules",
      "additionalProperties": {
        "type": "object",
        "properties": {
          "endpoint": {
            "type": "string",
            "minLength": 1
          },
          "logoutPath": {
            "type": "string",
            "minLength": 1,
            "format": "relative-uri"
          },
          "logoutMethod": {
            "type": "string",
            "enum": [
              "PUT",
              "POST",
              "GET"
            ]
          }
        },
        "additionalProperties": false
      }
    },
    "logout": {
      "type": "object",
      "properties": {
        "logoutEndpoint": {
          "type": "string",
          "minLength": 1,
          "format": "relative-uri"
        },
        "logoutPage": {
          "type": "string",
          "minLength": 1,
          "format": "uri"
        }
      },
      "format": "logout-rules",
      "additionalProperties": false
    },
    "login": {
      "type": "object",
      "required": [
        "callbackEndpoint"
      ],
      "properties": {
        "callbackEndpoint": {
          "type": "string",
          "minLength": 1,
          "format": "relative-uri"
        }
      },
      "additionalProperties": false
    },
    "whitelistService": {
      "type": "object",
      "required": [
        "endpoint"
      ],
      "properties": {
        "endpoint": {
          "type": "string",
          "minLength": 1,
          "format": "relative-uri"
        }
      },
      "additionalProperties": false
    },
    "compression": {
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "minSize": {
          "type": "integer",
          "minimum": 1
        }
      },
      "additionalProperties": false
    },
    "websockets": {
      "type": "object",
      "required": [
        "enabled"
      ],
      "properties": {
        "enabled": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    },
    "errorPage": {
      "type": "array",
      "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"
          }
        }
      },
      "additionalProperties": false
    }
  },
  "$comment": "Based on https://github.wdf.sap.corp/xs2/approuter.js/blob/master/lib/configuration/schemas/xs-app-schema.json",
  "$defs": {
    "sourceSchema": {
      "type": [
        "string",
        "object"
      ],
      "minLength": 1,
      "format": "regex",
      "required": [
        "path"
      ],
      "properties": {
        "path": {
          "type": "string",
          "minLength": 1,
          "format": "regex"
        },
        "matchCase": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    },
    "scopesSchema": {
      "type": [
        "string",
        "array",
        "object"
      ],
      "minProperties": 1,
      "items": {
        "type": "string",
        "minLength": 1
      },
      "properties": {
        "GET": {
          "$ref": "#/$defs/scopeTemplate"
        },
        "POST": {
          "$ref": "#/$defs/scopeTemplate"
        },
        "HEAD": {
          "$ref": "#/$defs/scopeTemplate"
        },
        "PUT": {
          "$ref": "#/$defs/scopeTemplate"
        },
        "DELETE": {
          "$ref": "#/$defs/scopeTemplate"
        },
        "TRACE": {
          "$ref": "#/$defs/scopeTemplate"
        },
        "PATCH": {
          "$ref": "#/$defs/scopeTemplate"
        },
        "OPTIONS": {
          "$ref": "#/$defs/scopeTemplate"
        },
        "CONNECT": {
          "$ref": "#/$defs/scopeTemplate"
        },
        "default": {
          "$ref": "#/$defs/scopeTemplate"
        }
      },
      "minLength": 1,
      "minItems": 1,
      "additionalProperties": false
    },
    "scopeTemplate": {
      "type": [
        "string",
        "array"
      ],
      "minLength": 1,
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 1
      }
    }
  }
}
