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

feat: allow for the retrieval of plugin schema for loaded plugins #1

Merged
merged 2 commits into from
Jan 28, 2022

Conversation

mikefero
Copy link
Contributor

@mikefero mikefero commented Jan 27, 2022

Calling SchemaAsJSON after LoadSchema has been executed for plugins will return the plugin configuration schema. This can be used for UI generation; similar to the endpoint /schema/plugins/:name Kong Gateway provides.

TODO

  • - Add more tests for SchemaAsJSON

@mikefero mikefero added the work in progress PR is a work in progress label Jan 27, 2022
@@ -74,6 +73,114 @@ _G["load_plugin_schema"] = function(plugin_schema_string)
return nil, "error initializing schema for plugin: " .. err
end
end

-- Remove functions from a schema definition so that
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to remove the need for extra patching these functions were copied from kong/api/api_helpers.lua and kong/api/routes/kong.lua which included multiple required modules and contained c bindings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upstream Kong is tolerant of patches. We could send a patch to move these functions into a different lua file, which this code directly consumes. Only possible if there are no changes in these functions (that can't be refactored upstream).

internal/vm/setup.go Show resolved Hide resolved
Copy link
Member

@hbagdi hbagdi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good directionally.

internal/vm/setup.go Show resolved Hide resolved
plugin/validator_test.go Show resolved Hide resolved
@mikefero mikefero removed the work in progress PR is a work in progress label Jan 28, 2022
@@ -0,0 +1,55 @@
local typedefs = require "kong.db.schema.typedefs"
local url = require "patched.url"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stole this from the patch as well; wonder if there is something we can do which circumvents all the known modules used by Kong Gateway which use C libraries? (just thinking out loud here for the future).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, when I did all of this, my goal was to keep the patches to a minimum.


// Parse using DOM style with the map[string]interface{}
// This is simpler than trying to stuff a dynamic array into a static
// structure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, it is just more code and a bit harder to grok. A simple assert.JSONeq would suffice as well. No changes required. This is good as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah the grok is def a negative, we can always changes it later if we find it to be cumbersome in the future.

@hbagdi hbagdi merged commit ec02f77 into main Jan 28, 2022
@hbagdi hbagdi deleted the feat/plugin-schema-as-json branch January 28, 2022 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants