You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Good afternoon. Need your help.
I am using openapi: 3.0.0 and github.com/oapi-codegen/nethttp-middleware v1.0.2 library for data validation.
I am trying to upload a photo file to the server but I am facing the following problem.
request body has an error: failed to decode request body: path attachment: unsupported content type \"image/png\”
My swagger file looks like this
I suspect the error occurs github.com/getkin/kin-openapi/openapi3filter/req_resp_decoder.go on line 1462.
we send image contentType = image/png to contentType = multipart/form-data for validation and get an error.
var value any
if _, value, err = decodeBody(part, http.Header(part.Header), valueSchema, subEncFn); err != nil {
if v, ok := err.(*ParseError); ok {
return nil, &ParseError{path: []any{name}, Cause: v}
}
return nil, fmt.Errorf(“part %s: %w”, name, err)
}
at this point we expect contentType = multipart/form-data but get another one contentType = image/png and return with an error.
decoder, ok := bodyDecoders[mediaType]
if !ok {
return "", nil, &ParseError{
Kind: KindUnsupportedFormat,
Reason: fmt.Sprintf("%s %q", prefixUnsupportedCT, mediaType),
}
}
to solve this problem you need to put inside bodyDecoders not only contentType=multipart/form-data but also all contentType and encoding lists (image/png, image/jpeg and so on) in bodyDecoders.
Activity