cdb = T.string():optional(), -- path to CDB file, required for CDB
method = T.enum({ "body", "header", "query" }):optional(), -- how to pass input
encode = T.enum({ "json", "messagepack" }):optional(), -- how to encode input (if relevant)
- timeout = T.transform(
- T.one_of({T.number(), T.string()}),
- lua_util.parse_time_interval
- ):optional(),
+ timeout = T.transform(T.number({ min = 0 }), function(val)
+ if type(val) == "number" then
+ return val
+ elseif type(val) == "string" then
+ return lua_util.parse_time_interval(val)
+ end
+ return val
+ end):optional(),
})
-- Storage for CDB instances
exports.map_schema = T.one_of({
T.string(), -- 'http://some_map'
T.array(T.string()), -- ['foo', 'bar']
- T.one_of({ direct_map_schema, external_map_schema })
+ direct_map_schema, -- complex object with url/upstreams
+ external_map_schema -- external backend (HTTP API, etc)
})
return exports
local common_schema = T.table({
timeout = T.one_of({
T.number(),
- T.transform(T.string(), lutil.parse_time_interval)
+ T.transform(T.number({ min = 0 }), function(val)
+ if type(val) == "string" then
+ return lutil.parse_time_interval(val)
+ end
+ return val
+ end)
}):optional():doc({ summary = "Connection timeout (seconds)" }),
db = db_schema,
database = db_schema,
}):optional():doc({ summary = "Sentinel servers" }),
sentinel_watch_time = T.one_of({
T.number(),
- T.transform(T.string(), lutil.parse_time_interval)
+ T.transform(T.number({ min = 0 }), function(val)
+ if type(val) == "string" then
+ return lutil.parse_time_interval(val)
+ end
+ return val
+ end)
}):optional():doc({ summary = "Sentinel watch time" }),
sentinel_masters_pattern = T.string():optional():doc({ summary = "Sentinel masters pattern" }),
sentinel_master_maxerrors = T.one_of({
T.number(),
- T.transform(T.string(), tonumber)
+ T.transform(T.number(), function(val)
+ if type(val) == "string" then
+ return tonumber(val)
+ end
+ return val
+ end)
}):optional():doc({ summary = "Sentinel master max errors" }),
sentinel_username = T.string():optional():doc({ summary = "Sentinel username" }),
sentinel_password = T.string():optional():doc({ summary = "Sentinel password" }),
redis_version = T.one_of({
T.number(),
- T.transform(T.string(), tonumber)
+ T.transform(T.number(), function(val)
+ if type(val) == "string" then
+ return tonumber(val)
+ end
+ return val
+ end)
}):optional():doc({ summary = "Redis server version (6 or 7)" }),
}, { open = true })
local return_codes_schema = T.table({}, {
open = true,
- key = T.transform(T.string(), string.upper),
+ key = T.transform(T.string(), function(val)
+ if type(val) == "string" then
+ return string.upper(val)
+ end
+ return val
+ end),
extra = T.one_of({
T.array(T.string()),
-- Transform string to array, inner schema validates the result
local return_bits_schema = T.table({}, {
open = true,
- key = T.transform(T.string(), string.upper),
+ key = T.transform(T.string(), function(val)
+ if type(val) == "string" then
+ return string.upper(val)
+ end
+ return val
+ end),
extra = T.one_of({
T.array(T.one_of({
T.number(),
- T.transform(T.string(), tonumber)
+ T.transform(T.number(), function(val)
+ if type(val) == "string" then
+ return tonumber(val)
+ end
+ return val
+ end)
})),
-- Transform string or number to array, inner schema validates the result
T.transform(T.array(T.number()), function(val)