Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No ability in plugin schema to have a record with dynamic fields #13149

Open
1 task done
jaxtonw opened this issue Jun 4, 2024 · 3 comments
Open
1 task done

No ability in plugin schema to have a record with dynamic fields #13149

jaxtonw opened this issue Jun 4, 2024 · 3 comments
Labels
pending author feedback Waiting for the issue author to get back to a maintainer with findings, more details, etc... stale

Comments

@jaxtonw
Copy link

jaxtonw commented Jun 4, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Kong version ($ kong version)

Kong 2.8.4

Current Behavior

When defining a Kong plugin's schema, there is no way to allow for a record that does not have it's field attribute defined.

Minimal example:

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

return {
  name = "example",
  fields = {
    { consumer = typedefs.no_consumer },
    { config = {
        type = "record",
        fields = {
          { some_string = { type = "string", required = true } },
          { dynamic_record = { type = "record", required = false } }
        }
      }
    }
  }
}

The field some_string is fine, however dynamic_record produces a schema violation error: dynamic_record: field of type 'record' must declare 'fields'.

The inability to explicitly allow for a dynamic record as one of the fields is limiting. I want my users to be able to explicitly specify arbitrary key and value pairs as dynamic_record. I want both of these dynamic_records to be valid by the schema.

dynamic_record:
  key1: "value1"
dynamic_record:
  key1: 1
  key2: "other_value"

Expected Behavior

Should accept an arbitrary record type as a field

Steps To Reproduce

  1. Create a plugin schema
  2. Have one of the fields be of type record and do not define a field

Anything else?

The lack of documentation about fields that are of type record is ultimately the most addressable concern here. However, there should be a way to work around this as well.

@jaxtonw
Copy link
Author

jaxtonw commented Jun 4, 2024

Update:

A workaround was attempted that was not successful. Setting the fields for the record as fields = {} resulted in the schema violation error going away. However, when applying a configuration where dynamic_record has an added attribute, the configuration fails, as expected.

@Water-Melon
Copy link
Contributor

Water-Melon commented Jun 6, 2024

No, currently this is not supported. However, there is another workaround, which is to define dynamic_record as a string. Then, in your plugin, try to decode this string as JSON, for example:

local record = cjson.decode(conf.dynamic_record)

@chronolaw chronolaw added the pending author feedback Waiting for the issue author to get back to a maintainer with findings, more details, etc... label Jun 13, 2024
Copy link
Contributor

This issue is marked as stale because it has been open for 14 days with no activity.

@github-actions github-actions bot added the stale label Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending author feedback Waiting for the issue author to get back to a maintainer with findings, more details, etc... stale
Projects
None yet
Development

No branches or pull requests

3 participants