I am using Kong 3.3.0 in db-less mode using declarative yaml.
I'm trying to update the request body with a value present in the headers.
If I set a top-level JSON attribute it all works OK. When I try and update the value in a sub-object within the JSON then it fails; well, it sets the value but not exactly where I need it to be).
I am not sure if I am just specifying the JSON path incorrectly in the config or if this plugin doesn't actually support this functionality.
The relevant part of my kong.yaml when it works looks as follows:
- host: spring-template
name: spring_template_service
port: 12345
protocol: http
routes:
- name: spring_example
paths:
- /spring/example
strip_path: false
plugins:
- name: request-transformer
enabled: yes
config:
add:
body:
- newkey:newvalue
replace:
body:
- newkey:newvalue
When I pass in a request payload that looks as follows then the "newkey" attribute is either added if not present, or updated it it is present.
So for an empty input of:
{
}
it correctly returns:
{
"newkey": "newvalue"
}
I have confirmed this by inspecting the raw JSON that arrives at my Spring Boot service that Kong forwards the request onto.
As I say, I'm not sure how/if you can specify a sub object in the JSON but if I modify the relevant parts of the config above to be:
config:
add:
body:
- newkey.subkey:newvalue
replace:
body:
- newkey.subkey:newvalue
then in the JSON that is output from Kong I see this:
{
"newkey.subkey": "newvalue"
}
whereas what I was hoping for was:
{
"newkey": {
"subkey": "newvalue"
}
}
Does anyone know if the request-transformer plugin from Kong support this? The Kong documentation is pretty sparse and only covers very simple use-cases.
I have tried different patterns of config but none of them seem to give me what I need.
The only other option open is to write my own plugin to do what I need.