API网关Kong实践笔记

Kong[nginx]-20 插件schema.lua初探

2019-08-27  本文已影响0人  国服最坑开发

KONG专题目录


0x00 目的

本文想系统的调查一下Kong插件支持的参数输入UI格式,
顺便调查一下是否能实现自己的复杂参数的输入要求.

0x01 先来一张效果图:
效果图
0x02 代码实现

再来看一下, 是如何定制这些控制项:

local typedefs     = require "kong.db.schema.typedefs"

return {
    name   = "param_demo",
    fields = {
        {
            config = {
                type   = "record",
                fields = {
                    {
                        runTimes = {
                            type = "number",
                            default = 0,
                            between = {
                                0,
                                100
                            }
                        }
                    },
                    {
                        environment = {
                            type     = "string",
                            required = true,
                            one_of   = {
                                "production",
                                "development"
                            },
                            default  = "development"
                        }
                    },
                    {
                        prodMode = {
                            type     = "boolean",
                            required = true,
                            default  = false
                        }
                    },
                    {
                        httpActions = {
                            type     = "array",
                            elements = {
                                type   = "string",
                                one_of = {
                                    "GET",
                                    "POST"
                                }
                            }
                        }
                    },

                    {
                        appSettings = {
                            type   = "record",
                            fields = {
                                {
                                    appKey = {
                                        type = "string",
                                    }
                                },
                                {
                                    iOS = {
                                        type = "string"
                                    }
                                },
                                {
                                    Android = {
                                        type = "string"
                                    }
                                },
                            }
                        }
                    },
                },
            },
        },
    },
}

本来想调查一下是否能够在array下面嵌套一层record,
代码是能正常运行, 但是可能UI过于复杂, 没有UI提示,暂时作罢.

TODO

调查注释部分如何编写


KONG专题目录


上一篇下一篇

猜你喜欢

热点阅读