Skip to content

Commit 0fd582b

Browse files
authored
docs: automatic generate PDK docs by LDoc (#6321)
1 parent 6c233d3 commit 0fd582b

29 files changed

+511
-15
lines changed

.licenserc.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ header:
4242
# Exclude plugin-specific configuration files
4343
- 't/plugin/authz-casbin'
4444
- 't/coredns'
45+
- 'autodocs/'
4546

4647
comment: on-failure

apisix/core/config_etcd.lua

+26
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
-- limitations under the License.
1616
--
1717

18+
--- Get configuration information.
19+
--
20+
-- @module core.config_etcd
21+
1822
local table = require("apisix.core.table")
1923
local config_local = require("apisix.core.config_local")
2024
local log = require("apisix.core.log")
@@ -604,6 +608,28 @@ local function _automatic_fetch(premature, self)
604608
end
605609

606610

611+
---
612+
-- Create a new connection to communicate with the control plane.
613+
-- This function should be used in the `init_worker_by_lua` phase.
614+
--
615+
-- @function core.config.new
616+
-- @tparam string etcd directory to be monitored, e.g. "/routes".
617+
-- @tparam table opts Parameters related to the etcd client connection.
618+
-- The keys in `opts` are as follows:
619+
-- * automatic: whether to get the latest etcd data automatically
620+
-- * item_schema: the jsonschema that checks the value of each item under the **key** directory
621+
-- * filter: the custom function to filter the value of each item under the **key** directory
622+
-- * timeout: the timeout for watch operation, default is 30s
623+
-- * single_item: whether only one item under the **key** directory
624+
-- * checker: the custom function to check the value of each item under the **key** directory
625+
-- @treturn table The etcd client connection.
626+
-- @usage
627+
-- local plugins_conf, err = core.config.new("/custom_dir", {
628+
-- automatic = true,
629+
-- filter = function(item)
630+
-- -- called once before reload for sync data from admin
631+
-- end,
632+
--})
607633
function _M.new(key, opts)
608634
local local_conf, err = config_local.local_conf()
609635
if not local_conf then

apisix/core/config_local.lua

+25-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
-- limitations under the License.
1616
--
1717

18+
--- Get configuration information.
19+
--
20+
-- @module core.config_local
21+
1822
local file = require("apisix.cli.file")
1923
local schema = require("apisix.cli.schema")
2024

@@ -29,7 +33,27 @@ function _M.clear_cache()
2933
config_data = nil
3034
end
3135

32-
36+
---
37+
-- Get the local config info.
38+
-- The configuration information consists of two parts, user-defined configuration in
39+
-- `conf/config.yaml` and default configuration in `conf/config-default.yaml`. The configuration
40+
-- of the same name present in `conf/config.yaml` will overwrite `conf/config-default.yaml`.
41+
-- The final full configuration is `conf/config.yaml` and the default configuration in
42+
-- `conf/config-default.yaml` that is not overwritten.
43+
--
44+
-- @function core.config_local.local_conf
45+
-- @treturn table The configuration information.
46+
-- @usage
47+
-- -- Given a config item in `conf/config.yaml`:
48+
-- --
49+
-- -- apisix:
50+
-- -- ssl:
51+
-- -- fallback_sni: "a.test2.com"
52+
-- --
53+
-- -- you can get the value of `fallback_sni` by:
54+
-- local local_conf = core.config.local_conf()
55+
-- local fallback_sni = core.table.try_read_attr(
56+
-- local_conf, "apisix", "ssl", "fallback_sni") -- "a.test2.com"
3357
function _M.local_conf(force)
3458
if not force and config_data then
3559
return config_data

apisix/core/config_util.lua

+13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
-- See the License for the specific language governing permissions and
1515
-- limitations under the License.
1616
--
17+
18+
--- Collection of util functions
19+
--
20+
-- @module core.config_util
21+
1722
local core_tab = require("apisix.core.table")
1823
local str_byte = string.byte
1924
local str_char = string.char
@@ -68,6 +73,8 @@ function _M.cancel_clean_handler(item, idx, fire)
6873
end
6974

7075

76+
---
77+
-- Convert different time units to seconds as time units.
7178
-- Time intervals can be specified in milliseconds, seconds, minutes, hours, days and so on,
7279
-- using the following suffixes:
7380
-- ms milliseconds
@@ -81,6 +88,12 @@ end
8188
-- Multiple units can be combined in a single value by specifying them in the order from the most
8289
-- to the least significant, and optionally separated by whitespace.
8390
-- A value without a suffix means seconds.
91+
--
92+
-- @function core.config_util.parse_time_unit
93+
-- @tparam number|string Strings with time units, e.g. "60m".
94+
-- @treturn number Number of seconds after conversion
95+
-- @usage
96+
-- local seconds = core.config_util.parse_time_unit("60m") -- 3600
8497
function _M.parse_time_unit(s)
8598
local typ = type(s)
8699
if typ == "number" then

apisix/core/config_yaml.lua

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
-- See the License for the specific language governing permissions and
1515
-- limitations under the License.
1616
--
17+
18+
--- Get configuration information in Stand-alone mode.
19+
--
20+
-- @module core.config_yaml
21+
1722
local config_local = require("apisix.core.config_local")
1823
local yaml = require("tinyyaml")
1924
local log = require("apisix.core.log")

apisix/core/ctx.lua

+24
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
-- See the License for the specific language governing permissions and
1515
-- limitations under the License.
1616
--
17+
18+
--- Define the request context.
19+
--
20+
-- @module core.ctx
21+
1722
local core_str = require("apisix.core.string")
1823
local core_tab = require("apisix.core.table")
1924
local request = require("apisix.core.request")
@@ -301,6 +306,25 @@ do
301306
end,
302307
}
303308

309+
---
310+
-- Register custom variables.
311+
-- Register variables globally, and use them as normal builtin variables.
312+
-- Note that the custom variables can't be used in features that depend
313+
-- on the Nginx directive, like `access_log_format`.
314+
--
315+
-- @function core.ctx.register_var
316+
-- @tparam string name custom variable name
317+
-- @tparam function getter The fetch function for custom variables.
318+
-- @usage
319+
-- local core = require "apisix.core"
320+
--
321+
-- core.ctx.register_var("a6_labels_zone", function(ctx)
322+
-- local route = ctx.matched_route and ctx.matched_route.value
323+
-- if route and route.labels then
324+
-- return route.labels.zone
325+
-- end
326+
-- return nil
327+
-- end)
304328
function _M.register_var(name, getter)
305329
if type(getter) ~= "function" then
306330
error("the getter of registered var should be a function")

apisix/core/dns/client.lua

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
-- See the License for the specific language governing permissions and
1515
-- limitations under the License.
1616
--
17+
18+
--- Wrapped dns search client.
19+
--
20+
-- @module core.dns.client
21+
1722
local require = require
1823
local config_local = require("apisix.core.config_local")
1924
local log = require("apisix.core.log")

apisix/core/etcd.lua

+17-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
-- See the License for the specific language governing permissions and
1515
-- limitations under the License.
1616
--
17+
18+
--- Etcd API.
19+
--
20+
-- @module core.etcd
21+
1722
local fetch_local_conf = require("apisix.core.config_local").local_conf
1823
local array_mt = require("apisix.core.json").array_mt
1924
local etcd = require("resty.etcd")
@@ -364,7 +369,18 @@ function _M.delete(key)
364369
return res, nil
365370
end
366371

367-
372+
---
373+
-- Get etcd cluster and server version.
374+
--
375+
-- @function core.etcd.server_version
376+
-- @treturn table The response of query etcd server version.
377+
-- @usage
378+
-- local res, err = core.etcd.server_version()
379+
-- -- the res.body is as follows:
380+
-- -- {
381+
-- -- etcdcluster = "3.5.0",
382+
-- -- etcdserver = "3.5.0"
383+
-- -- }
368384
function _M.server_version()
369385
local etcd_cli, err = new()
370386
if not etcd_cli then

apisix/core/id.lua

+12-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
-- See the License for the specific language governing permissions and
1515
-- limitations under the License.
1616
--
17+
18+
--- Instance id of APISIX
19+
--
20+
-- @module core.id
21+
1722
local fetch_local_conf = require("apisix.core.config_local").local_conf
1823
local try_read_attr = require("apisix.core.table").try_read_attr
1924
local log = require("apisix.core.log")
@@ -84,7 +89,13 @@ function _M.init()
8489
end
8590
end
8691

87-
92+
---
93+
-- Returns the instance id of the running APISIX
94+
--
95+
-- @function core.id.get
96+
-- @treturn string the instance id
97+
-- @usage
98+
-- local apisix_id = core.id.get()
8899
function _M.get()
89100
return apisix_uid
90101
end

apisix/core/io.lua

+15-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,26 @@
1515
-- limitations under the License.
1616
--
1717

18+
--- I/O operations on files.
19+
--
20+
-- @module core.io
21+
1822
local open = io.open
1923

2024

2125
local _M = {}
2226

23-
27+
---
28+
-- Read the contents of a file.
29+
--
30+
-- @function core.io.get_file
31+
-- @tparam string file_name either an absolute path or
32+
-- a relative path based on the APISIX working directory.
33+
-- @treturn string The file content.
34+
-- @usage
35+
-- local file_content, err = core.io.get_file("conf/apisix.uid")
36+
-- -- the `file_content` maybe the APISIX instance id in uuid format,
37+
-- -- like "3f0e827b-5f26-440e-8074-c101c8eb0174"
2438
function _M.get_file(file_name)
2539
local f, err = open(file_name, 'r')
2640
if not f then

apisix/core/ip.lua

+15-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
-- See the License for the specific language governing permissions and
1515
-- limitations under the License.
1616
--
17+
18+
--- IP match and verify module.
19+
--
20+
-- @module core.ip
21+
1722
local json = require("apisix.core.json")
1823
local log = require("apisix.core.log")
1924
local ipmatcher = require("resty.ipmatcher")
@@ -36,7 +41,16 @@ function _M.create_ip_matcher(ip_list)
3641
return ip
3742
end
3843

39-
44+
---
45+
-- Verify that the given ip is a valid ip or cidr.
46+
--
47+
-- @function core.ip.validate_cidr_or_ip
48+
-- @tparam string ip IP or cidr.
49+
-- @treturn boolean True if the given ip is a valid ip or cidr, false otherwise.
50+
-- @usage
51+
-- local ip1 = core.ip.validate_cidr_or_ip("127.0.0.1") -- true
52+
-- local cidr = core.ip.validate_cidr_or_ip("113.74.26.106/24") -- true
53+
-- local ip2 = core.ip.validate_cidr_or_ip("113.74.26.666") -- false
4054
function _M.validate_cidr_or_ip(ip)
4155
local mask = 0
4256
local sep_pos = str_find(ip, "/")

apisix/core/json.lua

+17-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
-- See the License for the specific language governing permissions and
1515
-- limitations under the License.
1616
--
17+
18+
--- Wrapped serialization and deserialization modules for json and lua tables.
19+
--
20+
-- @module core.json
21+
1722
local cjson = require("cjson.safe")
1823
local json_encode = cjson.encode
1924
local clear_tab = require("table.clear")
@@ -95,8 +100,18 @@ local delay_tab = setmetatable({data = "", force = false}, {
95100
})
96101

97102

98-
-- this is a non-thread safe implementation
99-
-- it works well with log, eg: log.info(..., json.delay_encode({...}))
103+
---
104+
-- Delayed encoding of input data, avoid unnecessary encode operations.
105+
-- When really writing logs, if the given parameter is table, it will be converted to string in
106+
-- OpenResty by checking if there is a metamethod registered for `__tostring`, and if so,
107+
-- calling this method to convert it to string.
108+
--
109+
-- @function core.json.delay_encode
110+
-- @tparam string|table data The data to be encoded.
111+
-- @tparam boolean force Whether to clear the log buffer.
112+
-- @treturn table The table with the __tostring function overridden.
113+
-- @usage
114+
-- core.log.info("conf : ", core.json.delay_encode(conf))
100115
function _M.delay_encode(data, force)
101116
delay_tab.data = data
102117
delay_tab.force = force

apisix/core/log.lua

+16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
-- limitations under the License.
1616
--
1717

18+
--- Wrapped `ngx.log`.
19+
--
20+
-- @module core.log
21+
1822
local ngx = ngx
1923
local ngx_log = ngx.log
2024
local require = require
@@ -139,8 +143,20 @@ local delay_tab = setmetatable({
139143
})
140144

141145

146+
---
147+
-- Delayed execute log printing.
142148
-- It works well with log.$level, eg: log.info(..., log.delay_exec(func, ...))
143149
-- Should not use it elsewhere.
150+
--
151+
-- @function core.log.delay_exec
152+
-- @tparam function func Functions that need to be delayed during log printing.
153+
-- @treturn table The table with the res attribute overridden.
154+
-- @usage
155+
-- local function delay_func(param1, param2)
156+
-- return param1 .. " " .. param2
157+
-- end
158+
-- core.log.info("delay log print: ", core.log.delay_exec(delay_func, "hello", "world))
159+
-- -- then the log will be: "delay log print: hello world"
144160
function _M.delay_exec(func, ...)
145161
delay_tab.func = func
146162

0 commit comments

Comments
 (0)