Skip to content

Commit

Permalink
Added json schema for configuration file (#19)
Browse files Browse the repository at this point in the history
* Added schema.json

* Added correct description
  • Loading branch information
Evgeny Abramovich authored and evg4b committed Nov 21, 2023
1 parent 7fd4842 commit 53a4dc1
Showing 1 changed file with 274 additions and 0 deletions.
274 changes: 274 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"additionalProperties": false,
"properties": {
"mappings": {
"type": "array",
"description": "A list of mappings that describe how to forward requests.",
"minItems": 1,
"items": {
"$ref": "#/definitions/Mapping"
}
},
"http-port": {
"type": "integer",
"description": "Local HTTP listened port",
"default": 80,
"format": "int32"
},
"https-port": {
"type": "integer",
"description": "Local HTTPS listened port",
"default": 443,
"format": "int32"
},
"cert-file": {
"type": "string",
"description": "Path to HTTPS certificate file"
},
"key-file": {
"type": "string",
"description": "Path to matching for certificate private key"
},
"debug": {
"type": "boolean",
"description": "Show debug output",
"default": false
},
"proxy": {
"type": "string",
"description": "HTTP/HTTPS proxy to provide requests to real server (used system by default)",
"format": "uri"
},
"cache-config": {
"description": "Global cache configuration",
"type": "object",
"properties": {
"expiration-time": {
"description": "Cache expiration time",
"type": "string"
},
"clear-time": {
"description": "Expired cache clear time",
"type": "string"
},
"methods": {
"description": "List of http methods with can be cached",
"default": [
"GET"
],
"type": "array",
"items": {
"$ref": "#/definitions/Method"
}
}
},
"additionalProperties": false
}
},
"required": [
"mappings"
],
"definitions": {
"Mapping": {
"type": "object",
"oneOf": [
{
"type": "object",
"minProperties": 1,
"maxProperties": 1,
"additionalProperties": {
"type": "string"
}
},
{
"type": "object",
"properties": {
"from": {
"description": "The local host with protocol for the resource from which proxying will take place",
"type": "string"
},
"to": {
"description": "The target host with protocol for the resource to be proxied",
"type": "string"
},
"cache": {
"type": "array",
"description": "List the paths that will be cached.",
"items": {
"type": "string"
},
"minItems": 1
},
"mocks": {
"type": "array",
"description": "List the mocked requests",
"items": {
"$ref": "#/definitions/Mock"
},
"minItems": 1
},
"statics": {
"type": "array",
"description": "List of paths that will be served from the directory.",
"items": {
"$ref": "#/definitions/StaticDirectory"
},
"minItems": 1
}
},
"required": [
"from",
"to"
],
"additionalProperties": false
}
]
},
"Mock": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Mocked request path"
},
"method": {
"$ref": "#/definitions/Method",
"description": "Mocked request method"
},
"queries": {
"$ref": "#/definitions/Queries",
"description": "Mocked request queries"
},
"headers": {
"$ref": "#/definitions/Headers",
"description": "Mocked request headers"
},
"response": {
"description": "Mock response definition",
"oneOf": [
{
"$ref": "#/definitions/RawMockResponse"
},
{
"$ref": "#/definitions/FileMockResponse"
}
]
}
},
"additionalProperties": false,
"required": [
"path",
"response"
]
},
"RawMockResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"description": "HTTP response status code"
},
"delay": {
"$ref": "#/definitions/Duration",
"description": "Delay before sending the mock response"
},
"headers": {
"$ref": "#/definitions/Headers",
"description": "HTTP headers which will be sent in the mock response"
},
"raw": {
"type": "string",
"description": "Content which will be sent in the mock response"
}
},
"required": [
"code",
"raw"
],
"additionalProperties": false
},
"FileMockResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"description": "HTTP response status code"
},
"delay": {
"$ref": "#/definitions/Duration",
"description": "Delay before sending the mock response"
},
"headers": {
"$ref": "#/definitions/Headers",
"description": "HTTP headers which will be sent in the mock response"
},
"file": {
"type": "string",
"description": "Path to the file whose content will be sent in the mock response"
}
},
"required": [
"code",
"file"
],
"additionalProperties": false
},
"StaticDirectory": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Path where the static files will be served"
},
"dir": {
"type": "string",
"description": "Path to the folder from which the static files will be served"
},
"index": {
"type": "string",
"description": "The file witch will be returned if the requested file is not found. It should be a relative path within the dir folder",
"default": ""
}
},
"required": [
"path",
"dir"
],
"additionalProperties": false
},
"Headers": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"minProperties": 1
},
"Queries": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"minProperties": 1
},
"Method": {
"type": "string",
"enum": [
"GET",
"HEAD",
"POST",
"PUT",
"DELETE",
"CONNECT",
"OPTIONS",
"TRACE",
"PATCH"
]
},
"Duration": {
"type": "string",
"pattern": "^(\\d+h)?\\s*(\\d+m)?\\s*(\\d+s)?\\s*(\\d+ms)?\\s*(\\d+(us|µs))?\\s*(\\d+(ns))?$"
}
}
}

0 comments on commit 53a4dc1

Please sign in to comment.