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

deck file patch with path lengths > 128 characters #198

Closed
mheap opened this issue Aug 28, 2024 · 7 comments · Fixed by Kong/yaml#1 or Kong/deck#1405
Closed

deck file patch with path lengths > 128 characters #198

mheap opened this issue Aug 28, 2024 · 7 comments · Fixed by Kong/yaml#1 or Kong/deck#1405
Assignees

Comments

@mheap
Copy link
Member

mheap commented Aug 28, 2024

Running deck file patch on an OpenAPI spec where the path is > 128 characters in length throws an error:

# deck file patch -s simple20.yaml -o output20.yaml --selector=$..info --value='version:"2.2.0"' --verbose 2

2024/06/03 11:24:42 "level"=2 "msg"="parsed patch-instruction" "key"="version" "value"="2.2.0"

2024/06/03 11:24:42 "level"=2 "msg"="applying value-flags"
panic: invalid character '?' looking for beginning of object key string

goroutine 1 [running]:
github.com/kong/go-apiops/jsonbasics.ConvertToJSONInterface(0x101364468?)
github.com/kong/[email protected]/jsonbasics/jsonbasics.go:340 +0x90
github.com/kong/go-apiops/jsonbasics.ConvertToJSONobject(0x14000619bf0?)
github.com/kong/[email protected]/jsonbasics/jsonbasics.go:346 +0x1c
github.com/kong/deck/cmd.executePatch(0x140004a2c00?, {0x14000461100?, 0x0, 0x8})
github.com/kong/deck/cmd/file_patch.go:102 +0x8b0
github.com/spf13/cobra.(*Command).execute(0x140004bf800, {0x14000461080, 0x8, 0x8})
github.com/spf13/[email protected]/command.go:983 +0x840
github.com/spf13/cobra.(*Command).ExecuteC(0x14000442000)
github.com/spf13/[email protected]/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
github.com/spf13/[email protected]/command.go:1039
github.com/spf13/cobra.(*Command).ExecuteContext(...)
github.com/spf13/[email protected]/command.go:1032
github.com/kong/deck/cmd.Execute({0x1013615e0?, 0x14000393db0})
github.com/kong/deck/cmd/root.go:264 +0x68
main.main()
github.com/kong/deck/main.go:31 +0x20

Related GH issues:

go-yaml/yaml#1031
go-yaml/yaml#849

Proposed resolution: Fork go-yaml and use our own fork until the upstream PR is accepted

@Tieske
Copy link
Member

Tieske commented Aug 29, 2024

proposed fix: go-yaml/yaml#1037

@Prashansa-K
Copy link
Contributor

Prashansa-K commented Sep 11, 2024

@Tieske On merging the changes you suggested here in our own fork, we don't get errors anymore in case any path in OpenAPI spec >128 chars, but the rendered yaml doesn't consider the "path with len >128 chars" as a simple key. We get a complex key - complex value mapping in the output post a deck file patch. Adding SS (notice the ? before pathname and : before value get)
Image

Note: The rendered spec is still valid, just the path key isn't treated as simple anymore.
I just want to clarify if that is something we are okay with in deck output. @mheap
In my opinion, this shouldn't be a blocker as the spec and the yaml remains valid, but I wanted to know your opinion.

@Tieske
Copy link
Member

Tieske commented Sep 12, 2024

I do not follow. The example is an OAS file, so that is the input to deck, correct? so where do we create this file, if it was written by deck?

@Prashansa-K
Copy link
Contributor

Prashansa-K commented Sep 25, 2024

Okay. The above SS showed the output file, not input. Let me clarify with a new example below.

Here's the input SS. Path is of 145 chars.
Image

On running deck file patch -s test.yaml -o output20.yaml --selector=$..info --value='version:"2.2.0"', we don't get any errors. The output file is generated properly with valid yaml. I was just pointing out that in the output file, the 145 char path becomes a complex yaml key-value pair.

Image
The yaml is valid and can be fed to the deck file patch command again.

@Prashansa-K
Copy link
Contributor

I wanted to clarify that does this change from a simple key input to a "complex key" output need to be documented somewhere for deck?

@Prashansa-K
Copy link
Contributor

@mheap I had a word with Thijs about the yaml output changes. The generated yaml (with complex key mapping) works fine with other deck commands like patch, openapi2kong, etc. and a subsequent deck sync works fine as well.
Let us know if we still need to do something about the complex key change or document it out somewhere. To be fair, it is not a behaviour change, as the yaml is valid and works with the rest of the stuff, it is more of a visualisation change.

To clarify: the complex key yaml output shows up only if the path length is >128 characters. Otherwise, the output is a simple key mapping (as earlier).

@mheap
Copy link
Member Author

mheap commented Sep 25, 2024

No changes needed elsewhere. Please ship the fix

Prashansa-K added a commit to Kong/deck that referenced this issue Sep 25, 2024
This change allows deck commands to process OAS files with
path lengths > 128 characters which was a limitation from an
underlying library. This is fixed in the fork created in Kong
git account.

Fixes: Kong/go-apiops#198
Prashansa-K added a commit to Kong/deck that referenced this issue Sep 25, 2024
This change allows deck commands to process OAS files with
path lengths > 128 characters which was a limitation from an
underlying library. This is fixed in the fork created in Kong
git account.

Fixes: Kong/go-apiops#198
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants