-
Notifications
You must be signed in to change notification settings - Fork 40
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
fix: update empty slices in kong entities #426
base: main
Are you sure you want to change the base?
Conversation
LUIROTH seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
1 similar comment
LUIROTH seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
As best I recall, go-kong fields are typically Are you able to use the Some way to override the normal JSON tags in a struct would be ideal, so that you selectively toggle Edit: @czeslavo suggested using pointers to slices (or other types), which lets you distinguish between omission and an explicit empty slice (case @zekth says https://github.com/LukaGiorgadze/gonull may let achieve the same, though I'm not fully sure what that would look like--the library docs are bit light. Either of these would be a breaking type change, however--AFAIK there's nothing still that'd let us toggle between marshal results with the existing types, so it'd be a major release if so, and one I'd still be reluctant to make due to the upgrade burden. PUTing to clear these is probably still the better option. |
Catching up on this, exposing fields with OmitPointer *[]*string `json:"omitpointer,omitempty" In the current state of things i'd +1 @rainest on:
If we want to not touch the types and have Line 116 in 8f4d15c
So that would mean |
It does already, right? https://github.com/Kong/go-kong/blob/main/kong/request.go#L22-L37 I feel like this missing bit is |
Hi @rainest, @zekth and @pmalek, I also though of a custom Mashaller for the entities that can dynamically remove nil values but keep empty values. Would this work for you?
With this it should be possible ignore nil values but keep the empty values. |
@pmalek my bad i haven't dug deep into the implementation, assuming the underlying method wasn't doing any reflection. @CyberGuestNo1 for this case that would mean we won't be able to set back a value to its default from kong POV. Let's take example key-auth: https://docs.konghq.com/hub/kong-inc/key-auth/configuration/ If you want to fallback on kong default you'd need to send After twisting this from one way to another, if we really want to achieve |
@zekth yes you are right. We should not change the behaviour of the config in plugins or nested objects.
I think jsonpatch would make this issue much more complicated. The concrete issue we are facing is that we can't set the "methods" property of a route to an empty list with the Update Method. |
I encountered similar issue for a PATCH request, just that in this case nil value should not be omitted. So while the above approach works for a given constraint (skipping nil but not empty), it may not work for others. I have similar suggestion but a slightly different approach captured in ticket. would be happy to get community feedback. |
Summary
Bugfix: Could not update service, route or plugin with empty slices because it was removed through the
omitempty
JSON struct tag.Note: This bug is only fixed for services, routes or plugins. WIth other entities this problem may still occour.
Manuel Gugel <manuel_sebastian.gugel@mercedes-benz.com>, Mercedes-Benz Tech Innovation GmbH, imprint