Skip to content

Instantly share code, notes, and snippets.

@mehuled
Created April 14, 2024 12:56
Show Gist options
  • Save mehuled/920401c3f2cd2dd32fd257302bab98ad to your computer and use it in GitHub Desktop.
Save mehuled/920401c3f2cd2dd32fd257302bab98ad to your computer and use it in GitHub Desktop.
local typedefs = require "kong.db.schema.typedefs"
local PLUGIN_NAME = "add-header"
local schema = {
name = PLUGIN_NAME,
fields = {
-- the 'fields' array is the top-level entry with fields defined by Kong
{ consumer = typedefs.no_consumer }, -- this plugin cannot be configured on a consumer (typical for auth plugins)
{ protocols = typedefs.protocols_http },
{ config = {
-- The 'config' record is the custom part of the plugin schema
type = "record",
fields = {
-- a standard defined field (typedef), with some customizations
{ request_header = typedefs.header_name {
required = true,
default = "Hello-World" } },
{ response_header = typedefs.header_name {
required = true,
default = "Bye-World" } },
{ ttl = { -- self defined field
type = "integer",
default = 600,
required = true,
gt = 0, }}, -- adding a constraint for the value
},
entity_checks = {
-- add some validation rules across fields
-- the following is silly because it is always true, since they are both required
{ at_least_one_of = { "request_header", "response_header" }, },
-- We specify that both header-names cannot be the same
{ distinct = { "request_header", "response_header"} },
},
},
},
},
}
return schema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment