swaggest / openapi-go

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

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

Closed dikac closed 4 months ago

dikac commented 5 months 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 4 months 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?

vearutop commented 4 months ago

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