Kong / Kong/kong-python-pdk

Custom Validation of Schema

Open
#45 3 comments 4 reactions 0 assignees View on GitHub
documentation enhancement
Dominant language
Python
Stars
48
Forks
16
PR merge metrics
No merged PRs in 30d

Description

Hi,

I'm unable to get custom validators for the `Schema` working.

The docs say:
> Schema defines the config schema of plugin, it shares the same syntax as it’s a Lua plugin.

So I would assume this would work:
```
def some_validator():
pass

Schema = ({'some_config': {'custom_validator': some_validator, 'type': 'string'}},)
```
But this produces the following error:
`TypeError: Object of type function is not JSON serializable`

If I make the value a string, e.g.
```
def some_validator():
pass

Schema = ({'some_config': {'custom_validator': 'some_validator', 'type': 'string'}},)
```
I get the following error:
`custom_validator = "expected a function"`

How can I do custom validation with the Python PDK?
My use case is to encrypt a field before it is stored, since the Python PDK cannot access environment variables.

In general a more complete example showing how the Lua schema is used in the Python PDK would be great!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing how the Python PDK serializes Schema values and handles the custom_validator field, using the reported JSON serialization and expected-function errors as the starting cases. Done means determining whether Python custom validators are supported and either making the documented schema form work or documenting the supported approach with a complete example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.