swaggest / openapi-go

OpenAPI structures for Go
https://pkg.go.dev/github.com/swaggest/openapi-go/openapi3
MIT License
223 stars 18 forks source link

checkJSONBodyContentType failed to tolerate multipart/form-data with boundary #115

Open dikac opened 3 weeks ago

dikac commented 3 weeks ago

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

vearutop commented 3 days ago

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?