-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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(aws-lambda): add new configuration field empty_arrays_mode
to control empty array decoding behavior
#13084
Conversation
changelog/unreleased/kong/feat-aws-lambda-decode-empty-array.yml
Outdated
Show resolved
Hide resolved
kong/plugins/aws-lambda/schema.lua
Outdated
@@ -116,6 +116,13 @@ return { | |||
default = "v1", | |||
one_of = { "v1", "v2" } | |||
} }, | |||
{ empty_arrays_mode = { -- TODO: this config field is added for backward compatibility and will be removed in next major version | |||
description = "An optional value that defines whether Kong should send empty arrays(returned by Lambda function) as `[]` arrays or `{}` objects in JSON responses. The value `legacy` means Kong will send empty arrays as `{}` objects in response", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this?
description = "An optional value that defines whether Kong should send empty arrays(returned by Lambda function) as `[]` arrays or `{}` objects in JSON responses. The value `legacy` means Kong will send empty arrays as `{}` objects in response", | |
description = "An optional value that defines whether Kong should send empty arrays(returned by Lambda function) as `[]` arrays or `{}` objects in JSON responses. The value `legacy` means Kong will send empty arrays `[]` as `{}` objects in response", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
I would love to see if we have a compatibility test for that new field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small comment.
3657ea2
to
5ace553
Compare
…control empty array decoding behavior
Co-authored-by: Yusheng Li <leeys.top@gmail.com>
Co-authored-by: Zachary Hu <6426329+outsinre@users.noreply.github.com>
5ace553
to
159fd91
Compare
…control empty array decoding behavior (#13084) Co-authored-by: Yusheng Li <leeys.top@gmail.com> Co-authored-by: Zachary Hu <6426329+outsinre@users.noreply.github.com>
…oxy integration and legacy empty arrays mode (#13381) This PR fixes a bug that introduced by #13084, that when is_proxy_integration mode is set to true with empty_arrays_mode set to legacy, and lambda function returns multiValueHeader that contains a Content-Type with single value array, the plugin cannot work correctly. The multiValueHeaders field in the proxy integration response can be an array even if the header has only one value. I've tested AWS API gateway and the Kong gateway before #13084 and confirmed that both would work fine with Content-Type single value array inside the mutliValueHeader response field. The reason of #13084 brings in this issue is that before #13084 we did not have any logic about reading Content-Type so no problem existed. The single value array will goes into kong.response.exit and normalized automatically. This PR fixes the problem that when Content-Type returned by the lambda function is ["application-json"], the plugin cannot execute the if-block correctly due to not being able to call the lower function on the array(table) object. Although there is a tiny possibility that the user will encounter this issue(because I think mostly people will define Content-Type inside the headers field instead of the mutliValueHeaders since it should be only one value), it is still good to fix this issue and let it behave like before. https://konghq.atlassian.net/browse/FTI-6100 --------- Co-authored-by: Zachary Hu <6426329+outsinre@users.noreply.github.com>
…oxy integration and legacy empty arrays mode (#13381) This PR fixes a bug that introduced by #13084, that when is_proxy_integration mode is set to true with empty_arrays_mode set to legacy, and lambda function returns multiValueHeader that contains a Content-Type with single value array, the plugin cannot work correctly. The multiValueHeaders field in the proxy integration response can be an array even if the header has only one value. I've tested AWS API gateway and the Kong gateway before #13084 and confirmed that both would work fine with Content-Type single value array inside the mutliValueHeader response field. The reason of #13084 brings in this issue is that before #13084 we did not have any logic about reading Content-Type so no problem existed. The single value array will goes into kong.response.exit and normalized automatically. This PR fixes the problem that when Content-Type returned by the lambda function is ["application-json"], the plugin cannot execute the if-block correctly due to not being able to call the lower function on the array(table) object. Although there is a tiny possibility that the user will encounter this issue(because I think mostly people will define Content-Type inside the headers field instead of the mutliValueHeaders since it should be only one value), it is still good to fix this issue and let it behave like before. https://konghq.atlassian.net/browse/FTI-6100 --------- Co-authored-by: Zachary Hu <6426329+outsinre@users.noreply.github.com> (cherry picked from commit 6f5684d)
Summary
This PR adds a new configuration field
empty_arrays_mode
to control the behaviour that whether Kong will transform an empty array[]
(returned by Lambda function) into an empty object{}
when enabled aws-lambda plugin in the response.Essentially this PR is just a small bugfix for not previously enabling
decode_array_with_array_mt
when decoding Lambda function's response. However, enablingdecode_array_with_array_mt
may bring unexpected behaviour changes on the user side(since the wrong behaviour itself has existed for long), so we decided to add a new field to keep backward compatibility, and remove this field in the next major version to let the correct behaviour(keep empty arrrays as is) to become the default behaviour in the next major version.Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
FTI-5937
KAG-4622
KAG-4615