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

Support array field for Request DTO #4025

Closed
shyandsy opened this issue Mar 28, 2024 · 4 comments · Fixed by #4026
Closed

Support array field for Request DTO #4025

shyandsy opened this issue Mar 28, 2024 · 4 comments · Fixed by #4026

Comments

@shyandsy
Copy link
Contributor

shyandsy commented Mar 28, 2024

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

It supports array field object in the api specification right now, and it should be work in controller

GetVersionReq {
		Statuses                     []string   `form:"statuses[],omitempty,optional"`
}

unfortunately, it doesn't work because there is a tiny mass in httpx package. The form.Get method only return one string rather than string array
image

Describe the solution you'd like
A clear and concise description of what you want to happen.

we should not use the Get method directly if we wanna support array field..... btw, I am curiose why Go design the method like this. It make no sense....right?

Get(key string) string

image

Alternatively, I will access the map directly like what saying in the comment

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@shyandsy shyandsy changed the title make it support array field for Request DTO Support array field for Request DTO Mar 28, 2024
@kevwan kevwan linked a pull request Mar 30, 2024 that will close this issue
@kevwan
Copy link
Contributor

kevwan commented Mar 30, 2024

fixed by #4026

@kevwan kevwan closed this as completed Mar 30, 2024
@ch3nnn
Copy link
Contributor

ch3nnn commented Apr 1, 2024

fixed by #4026

I found this PR flawed. see #4015 (comment)

bug url example:

"/a?name=hello&age=18&percent=3.4&statuses=try"

error parse statuses is nil, instead of []string{"try"}.

=== RUN   TestParseForm
    requests_test.go:31: 
        	Error Trace:	/Users/chentong/project/go/go-zero/rest/httpx/requests_test.go:31
        	Error:      	Expected nil, but got: &fmt.wrapError{msg:"fullName: `statuses`, error: `string: `try`, error: `invalid character 'y' in literal true (expecting 'u')``", err:(*fmt.wrapError)(0x14000098900)}
        	Test:       	TestParseForm
    requests_test.go:35: 
        	Error Trace:	/Users/chentong/project/go/go-zero/rest/httpx/requests_test.go:35
        	Error:      	Not equal: 
        	            	expected: []string{"try"}
        	            	actual  : []string(nil)
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1,4 +1,2 @@
        	            	-([]string) (len=1) {
        	            	- (string) (len=3) "try"
        	            	-}
        	            	+([]string) <nil>
        	            	 
        	Test:       	TestParseForm
--- FAIL: TestParseForm (0.00s)

预期:[]string{"try"}
实际:[]string(nil)

@shyandsy @kevwan

@shyandsy
Copy link
Contributor Author

shyandsy commented Apr 1, 2024 via email

@shyandsy
Copy link
Contributor Author

shyandsy commented Apr 9, 2024

@ch3nnn @kevin0527

#4052

this is the new pr for this issue, could you guys help to check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants