I'd like to know if it's possible to have a Kong custom plugin with a configuration field which can have one of these two different types: string
or array
. And in case it's possible, I'd like to know how.
Example usage (with Kubernetes Ingress Controller):
with a single string:
apiVersion: configuration.konghq.com/v1kind: KongPluginmetadata: name: my-plugin-example annotations: kubernetes.io/ingress.class: kongplugin: my-pluginconfig: different_types: | value1 value2 value3
with an array of strings:
apiVersion: configuration.konghq.com/v1kind: KongPluginmetadata: name: my-plugin-example annotations: kubernetes.io/ingress.class: kongplugin: my-pluginconfig: different_types: - "value1" - "value2" - "value3"
Here's what I tried (file schema.lua
):
local typedefs = require("kong.db.schema.typedefs")local PLUGIN_NAME = "my-plugin"return { name = PLUGIN_NAME, fields = { { consumer = typedefs.no_consumer }, { protocols = typedefs.protocols_http }, { config = { type = "record", fields = { { different_types = { description = "This is a config parameter with flexible type", one_of = { { type = "string" }, { type = "array", elements = { type = "string" },}, }, required = false, },} }, },}, },}
However, I'm getting error type = "required field missing"
:
2024/05/08 15:42:51 [error] 1#0: init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:772: error loading plugin schemas: on plugin 'my-plugin': [off] 2 schema violations (fields.3: { fields = { [2] = { type = "required field missing" } }}; different_types: missing type declaration)stack traceback: [C]: in function 'assert' /usr/local/share/lua/5.1/kong/init.lua:772: in function 'init' init_by_lua(nginx-kong.conf:54):3: in main chunknginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:772: error loading plugin schemas: on plugin 'my-plugin': [off] 2 schema violations (fields.3: { fields = { [2] = { type = "required field missing" } }}; different_types: missing type declaration)stack traceback: [C]: in function 'assert' /usr/local/share/lua/5.1/kong/init.lua:772: in function 'init' init_by_lua(nginx-kong.conf:54):3: in main chunk