mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-15 09:21:26 +08:00
change: use Lua table directly to avoid JSON string. (#580)
This commit is contained in:
parent
cfc228d886
commit
8caa2d9889
@ -1,9 +1,8 @@
|
|||||||
local schema = require('apisix.core.schema')
|
local schema = require('apisix.core.schema')
|
||||||
local json = require("apisix.core.json")
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
|
|
||||||
local _M = {version = 0.1}
|
local _M = {version = 0.2}
|
||||||
|
|
||||||
|
|
||||||
setmetatable(_M, {__index = schema})
|
setmetatable(_M, {__index = schema})
|
||||||
@ -176,6 +175,14 @@ local health_checker = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
local valid_ip_fmts = {
|
||||||
|
{pattern = "^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"},
|
||||||
|
{pattern = "^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}"
|
||||||
|
.. "/[0-9]{1,2}$"},
|
||||||
|
{pattern = "^([a-f0-9]{0,4}:){0,8}(:[a-f0-9]{0,4}){0,8}$"}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
local upstream_schema = {
|
local upstream_schema = {
|
||||||
type = "object",
|
type = "object",
|
||||||
properties = {
|
properties = {
|
||||||
@ -247,69 +254,57 @@ local upstream_schema = {
|
|||||||
additionalProperties = false,
|
additionalProperties = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local route = {
|
||||||
local route = [[{
|
type = "object",
|
||||||
"type": "object",
|
properties = {
|
||||||
"properties": {
|
methods = {
|
||||||
"methods": {
|
type = "array",
|
||||||
"type": "array",
|
items = {
|
||||||
"items": {
|
description = "HTTP method",
|
||||||
"description": "HTTP method",
|
type = "string",
|
||||||
"type": "string",
|
enum = {"GET", "POST", "PUT", "DELETE", "PATCH", "HEAD",
|
||||||
"enum": ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD",
|
"OPTIONS", "CONNECT", "TRACE"}
|
||||||
"OPTIONS", "CONNECT", "TRACE"]
|
|
||||||
},
|
},
|
||||||
"uniqueItems": true
|
uniqueItems = true,
|
||||||
},
|
},
|
||||||
"service_protocol": {
|
service_protocol = {
|
||||||
"enum": [ "grpc", "http" ]
|
enum = {"grpc", "http"}
|
||||||
},
|
},
|
||||||
"desc": {"type": "string", "maxLength": 256},
|
desc = {type = "string", maxLength = 256},
|
||||||
"plugins": ]] .. json.encode(plugins_schema) .. [[,
|
plugins = plugins_schema,
|
||||||
"upstream": ]] .. json.encode(upstream_schema) .. [[,
|
upstream = upstream_schema,
|
||||||
"uri": {
|
uri = {
|
||||||
"type": "string"
|
type = "string",
|
||||||
},
|
},
|
||||||
"host": {
|
host = {
|
||||||
"type": "string",
|
type = "string",
|
||||||
"pattern": "^\\*?[0-9a-zA-Z-.]+$"
|
pattern = "^\\*?[0-9a-zA-Z-.]+$",
|
||||||
},
|
},
|
||||||
"vars": {
|
vars = {
|
||||||
"type": "array",
|
type = "array",
|
||||||
"items": {
|
items = {
|
||||||
"description": "Nginx builtin variable name and value",
|
description = "Nginx builtin variable name and value",
|
||||||
"type": "array"
|
type = "array",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"remote_addr": {
|
remote_addr = {
|
||||||
"description": "client IP",
|
description = "client IP",
|
||||||
"type": "string",
|
type = "string",
|
||||||
"anyOf": [
|
anyOf = valid_ip_fmts,
|
||||||
{"pattern": "^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"},
|
|
||||||
{"pattern": "^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}]]
|
|
||||||
.. [[/[0-9]{1,2}$"},
|
|
||||||
{"pattern": "^([a-f0-9]{0,4}:){0,8}(:[a-f0-9]{0,4}){0,8}$"}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"service_id": ]] .. json.encode(id_schema) .. [[,
|
service_id = id_schema,
|
||||||
"upstream_id": ]] .. json.encode(id_schema) .. [[,
|
upstream_id = id_schema,
|
||||||
"id": ]] .. json.encode(id_schema) .. [[
|
id = id_schema,
|
||||||
},
|
},
|
||||||
"anyOf": [
|
anyOf = {
|
||||||
{"required": ["plugins", "uri"]},
|
{required = {"plugins", "uri"}},
|
||||||
{"required": ["upstream", "uri"]},
|
{required = {"upstream", "uri"}},
|
||||||
{"required": ["upstream_id", "uri"]},
|
{required = {"upstream_id", "uri"}},
|
||||||
{"required": ["service_id", "uri"]}
|
{required = {"service_id", "uri"}},
|
||||||
],
|
},
|
||||||
"additionalProperties": false
|
additionalProperties = false,
|
||||||
}]]
|
}
|
||||||
do
|
_M.route = route
|
||||||
local route_t, err = json.decode(route)
|
|
||||||
if err then
|
|
||||||
error("invalid route: " .. route)
|
|
||||||
end
|
|
||||||
_M.route = route_t
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
_M.service = {
|
_M.service = {
|
||||||
@ -389,14 +384,6 @@ _M.global_rule = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
local valid_ip_fmts = {
|
|
||||||
{pattern = "^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"},
|
|
||||||
{pattern = "^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}"
|
|
||||||
.. "/[0-9]{1,2}$"},
|
|
||||||
{pattern = "^([a-f0-9]{0,4}:){0,8}(:[a-f0-9]{0,4}){0,8}$"}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
_M.stream_route = {
|
_M.stream_route = {
|
||||||
type = "object",
|
type = "object",
|
||||||
properties = {
|
properties = {
|
||||||
|
Loading…
Reference in New Issue
Block a user