postman-code-generators icon indicating copy to clipboard operation
postman-code-generators copied to clipboard

Go: Wrong code generation if body contains an empty string in string array

Open akshaybharambe14 opened this issue 3 years ago • 2 comments

Describe the bug Wrong Go code is generated if the request body of type array of string contains an empty string. ex. ["b", "", "a"]

To Reproduce Use following request body and generate go code

[
    "b",
    "",
    "a"
]

Expected code snippet and corresponding request Request -

curl --location --request POST 'https://example.com/users/roles' \
--header 'Content-Type: application/json' \
--data-raw '[
    "b",
    "",
    "a"
]'

Generated code - https://play.golang.org/p/kJuPMKHIm__y

  payload := strings.NewReader(`[`+"
"+`
    "b",`+"
"+`
    "",`+"
"+`
    "a"`+"
"+`
]`)

Expected code - https://play.golang.org/p/q35o4Ll4NMV

payload := strings.NewReader(`[
    "b",
    "",
    "a"
]`)

Screenshots N/A

Additional context I feel, additional spaces are causing problems. If we can omit the space and use raw body, this problem can be fixed.

Version of postman-code-generators/Postman app: Postman v8.8.0

akshaybharambe14 avatar Jul 20 '21 05:07 akshaybharambe14

@akshaybharambe14 This issue seems to have been fixed in the latest version of Postman (v10.13). Can you confirm? Screenshot 2023-04-26 at 3 21 53 PM

webholik avatar Apr 26 '23 09:04 webholik

Strange, I am using Version 10.13.6 and it is still producing the same result.

image image

akshaybharambe14 avatar May 15 '23 06:05 akshaybharambe14