{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://catalog.lintel.tools/schemas/schemastore/uncors-configuration/latest.json",
  "title": "Uncors configuration",
  "description": "Configuration file for uncors reverse proxy",
  "x-lintel": {
    "source": "https://raw.githubusercontent.com/evg4b/uncors/main/schema.json",
    "sourceSha256": "0414bb3a707fdfaa666f8c453e00da28eb8ad1600a0127d1553db495a25bf5c5",
    "fileMatch": [
      "*.uncors.yml",
      "*.uncors.yaml",
      ".uncors.yml",
      ".uncors.yaml"
    ],
    "parsers": [
      "yaml"
    ]
  },
  "type": "object",
  "properties": {
    "cache-config": {
      "type": "object",
      "description": "Global cache configuration",
      "properties": {
        "clear-time": {
          "description": "Expired cache clear time",
          "type": "string"
        },
        "expiration-time": {
          "description": "Cache expiration time",
          "type": "string"
        },
        "methods": {
          "default": [
            "GET"
          ],
          "description": "List of http methods with can be cached",
          "items": {
            "$ref": "#/$defs/Method"
          },
          "type": "array"
        }
      },
      "additionalProperties": false
    },
    "debug": {
      "default": false,
      "description": "Show debug output",
      "type": "boolean"
    },
    "mappings": {
      "description": "A list of mappings that describe how to forward requests. Ports are specified in the 'from' URL (e.g., <http://localhost:8080)>.",
      "items": {
        "$ref": "#/$defs/Mapping"
      },
      "minItems": 1,
      "type": "array"
    },
    "proxy": {
      "description": "HTTP/HTTPS proxy to provide requests to real server (used system by default)",
      "format": "uri",
      "type": "string"
    }
  },
  "additionalProperties": false,
  "required": [
    "mappings"
  ],
  "$defs": {
    "Duration": {
      "description": "Duration in human-readable format. Supported units are 'h' (hours), 'm' (minutes), 's' (seconds), 'ms' (milliseconds), 'us' (microseconds), 'ns' (nanoseconds).",
      "examples": [
        "3s",
        "1m 30s",
        "500ms",
        "1h 30m 15s 500ms 100us 200ns"
      ],
      "pattern": "^(\\d+h)?\\s*(\\d+m)?\\s*(\\d+s)?\\s*(\\d+ms)?\\s*(\\d+(us|µs))?\\s*(\\d+(ns))?$",
      "title": "Duration",
      "type": "string"
    },
    "FileMockResponse": {
      "type": "object",
      "description": "Mock response definition based on file content",
      "properties": {
        "code": {
          "$ref": "#/$defs/StatusCode",
          "description": "HTTP status code which will be sent in the mock response"
        },
        "delay": {
          "$ref": "#/$defs/Duration",
          "description": "Delay before sending the mock response"
        },
        "file": {
          "description": "Path to the file whose content will be sent in the mock response",
          "type": "string"
        },
        "headers": {
          "$ref": "#/$defs/Headers",
          "description": "HTTP headers which will be sent in the mock response"
        }
      },
      "required": [
        "code",
        "file"
      ],
      "additionalProperties": false
    },
    "Headers": {
      "type": "object",
      "description": "HTTP headers definition",
      "minProperties": 1,
      "additionalProperties": {
        "type": "string"
      }
    },
    "Mapping": {
      "oneOf": [
        {
          "type": "object",
          "description": "Host mapping definition",
          "maxProperties": 1,
          "minProperties": 1,
          "additionalProperties": {
            "type": "string"
          }
        },
        {
          "type": "object",
          "description": "Host mapping definition",
          "properties": {
            "cache": {
              "description": "List the paths that will be cached.",
              "items": {
                "type": "string"
              },
              "minItems": 1,
              "type": "array"
            },
            "from": {
              "description": "The local host with protocol and port for the resource from which proxying will take place (e.g., <http://localhost:8080)>. Port defaults to 80 for HTTP and 443 for HTTPS if not specified. HTTPS mappings use auto-generated certificates (requires CA certificate generated with 'uncors generate-certs').",
              "type": "string"
            },
            "mocks": {
              "description": "List the mocked requests",
              "items": {
                "$ref": "#/$defs/Mock"
              },
              "minItems": 1,
              "type": "array"
            },
            "options-handling": {
              "$ref": "#/$defs/OptionsHandling"
            },
            "rewrites": {
              "description": "List of paths that will be rewritten.",
              "items": {
                "$ref": "#/$defs/Rewrite"
              },
              "minItems": 1,
              "type": "array"
            },
            "scripts": {
              "description": "List of script handlers",
              "items": {
                "$ref": "#/$defs/Script"
              },
              "minItems": 1,
              "type": "array"
            },
            "statics": {
              "description": "List of paths that will be served from the directory.",
              "items": {
                "$ref": "#/$defs/StaticDirectory"
              },
              "minItems": 1,
              "type": "array"
            },
            "to": {
              "description": "The target host and protocol for the resource that needs to be proxied",
              "type": "string"
            }
          },
          "required": [
            "from",
            "to"
          ],
          "additionalProperties": false
        }
      ]
    },
    "Method": {
      "enum": [
        "GET",
        "HEAD",
        "POST",
        "PUT",
        "DELETE",
        "CONNECT",
        "OPTIONS",
        "TRACE",
        "PATCH"
      ],
      "type": "string"
    },
    "Mock": {
      "type": "object",
      "description": "Mocked request definition",
      "properties": {
        "headers": {
          "$ref": "#/$defs/Headers",
          "description": "Mocked request headers"
        },
        "method": {
          "$ref": "#/$defs/Method",
          "description": "Mocked request method"
        },
        "path": {
          "description": "Mocked request path",
          "type": "string"
        },
        "queries": {
          "$ref": "#/$defs/Queries",
          "description": "Mocked request queries"
        },
        "response": {
          "description": "Mock response definition",
          "oneOf": [
            {
              "$ref": "#/$defs/RawMockResponse"
            },
            {
              "$ref": "#/$defs/FileMockResponse"
            }
          ]
        }
      },
      "required": [
        "path",
        "response"
      ],
      "additionalProperties": false
    },
    "OptionsHandling": {
      "description": "OPTIONS request handling configuration",
      "properties": {
        "disabled": {
          "default": false,
          "description": "Disable OPTIONS request handling and all requests will be proxied to the target server",
          "type": "boolean"
        },
        "headers": {
          "$ref": "#/$defs/Headers",
          "description": "Custom headers to be sent in response to OPTIONS requests"
        },
        "status": {
          "$ref": "#/$defs/StatusCode",
          "description": "Custom status code to be sent in response to OPTIONS requests"
        }
      },
      "type": "object"
    },
    "Queries": {
      "type": "object",
      "description": "HTTP query parameters definition",
      "minProperties": 1,
      "additionalProperties": {
        "type": "string"
      }
    },
    "RawMockResponse": {
      "type": "object",
      "description": "Mock response definition based on raw content",
      "properties": {
        "code": {
          "$ref": "#/$defs/StatusCode"
        },
        "delay": {
          "$ref": "#/$defs/Duration",
          "description": "Delay before sending the mock response"
        },
        "headers": {
          "$ref": "#/$defs/Headers",
          "description": "HTTP headers which will be sent in the mock response"
        },
        "raw": {
          "description": "Content which will be sent in the mock response",
          "type": "string"
        }
      },
      "required": [
        "code",
        "raw"
      ],
      "additionalProperties": false
    },
    "Rewrite": {
      "type": "object",
      "properties": {
        "from": {
          "type": "string"
        },
        "host": {
          "type": "string"
        },
        "to": {
          "type": "string"
        }
      },
      "required": [
        "from",
        "to"
      ],
      "additionalProperties": false
    },
    "Script": {
      "type": "object",
      "description": "Script request handler definition",
      "oneOf": [
        {
          "not": {
            "required": [
              "file"
            ]
          },
          "required": [
            "script"
          ]
        },
        {
          "not": {
            "required": [
              "script"
            ]
          },
          "required": [
            "file"
          ]
        }
      ],
      "properties": {
        "file": {
          "description": "Path to script file",
          "type": "string"
        },
        "headers": {
          "$ref": "#/$defs/Headers",
          "description": "Request headers to match"
        },
        "method": {
          "$ref": "#/$defs/Method",
          "description": "Request method to match"
        },
        "path": {
          "description": "Request path to handle with script",
          "type": "string"
        },
        "queries": {
          "$ref": "#/$defs/Queries",
          "description": "Request query parameters to match"
        },
        "script": {
          "description": "Inline script code",
          "type": "string"
        }
      },
      "required": [
        "path"
      ],
      "additionalProperties": false
    },
    "StaticDirectory": {
      "type": "object",
      "description": "Static serving directory definition",
      "properties": {
        "dir": {
          "description": "Path to the folder from which the static files will be served",
          "type": "string"
        },
        "index": {
          "default": "",
          "description": "The file witch will be returned if the requested file is not found. It should be a relative path within the dir folder",
          "type": "string"
        },
        "path": {
          "description": "Path where the static files will be served",
          "type": "string"
        }
      },
      "required": [
        "path",
        "dir"
      ],
      "additionalProperties": false
    },
    "StatusCode": {
      "description": "HTTP response status code",
      "examples": [
        200,
        404,
        500
      ],
      "maximum": 599,
      "minimum": 100,
      "type": "integer"
    }
  }
}
