openapi-go icon indicating copy to clipboard operation
openapi-go copied to clipboard

checkJSONBodyContentType failed to tolerate multipart/form-data with boundary

Open dikac opened this issue 1 year ago • 1 comments

Describe the bug Content-Type: multipart/form-data; boundary=SOME-BOUNDARY would fail to parse when request tag contain formData and json

type UserList struct {
	Page      string       `formData:"page" json:"page"`
}

To Reproduce create a request struct with formData and json

type UserList struct {
	Page      string       `formData:"page" json:"page"`
}

send request with content type multipart/form-data with boundary

POST /users HTTP/1.1
Host: localhost:8234
User-Agent: insomnia/2023.3.0
Content-Type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY
Accept: */*
Content-Length: 98

--X-INSOMNIA-BOUNDARY
Content-Disposition: form-data; name="page"
A
--X-INSOMNIA-BOUNDARY--

would give Response

< HTTP/1.1 400 Bad Request
< Content-Length: 168
< Content-Type: application/json
< Date: Thu, 06 Jun 2024 14:17:45 GMT

Expected behavior Data decoded successfully without error

Additional context problem seems to came from function checkJSONBodyContentType

dikac avatar Jun 06 '24 14:06 dikac

Hello, swaggest/openapi-go library does not provide any request decoding facilities, could you clarify your use case? How do you decode request and how openapi-go is related?

vearutop avatar Jun 25 '24 10:06 vearutop

I'm closing this issue as likely not directly related to the lib, but feel free to reopen with more details.

vearutop avatar Jul 11 '24 09:07 vearutop