Skip to content

Commit 269c526

Browse files
committed
use FileBodyDecoder if the format is specified as binary
1 parent 90fb641 commit 269c526

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

openapi3filter/req_resp_decoder.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,13 @@ var headerCT = http.CanonicalHeaderKey("Content-Type")
12331233

12341234
const prefixUnsupportedCT = "unsupported content type"
12351235

1236+
func isBinary(schema *openapi3.SchemaRef) bool {
1237+
if schema == nil || schema.Value == nil {
1238+
return false
1239+
}
1240+
return schema.Value.Type.Is("string") && schema.Value.Format == "binary"
1241+
}
1242+
12361243
// decodeBody returns a decoded body.
12371244
// The function returns ParseError when a body is invalid.
12381245
func decodeBody(body io.Reader, header http.Header, schema *openapi3.SchemaRef, encFn EncodingFn) (
@@ -1246,8 +1253,14 @@ func decodeBody(body io.Reader, header http.Header, schema *openapi3.SchemaRef,
12461253
contentType = "text/plain"
12471254
}
12481255
}
1256+
12491257
mediaType := parseMediaType(contentType)
12501258
decoder, ok := bodyDecoders[mediaType]
1259+
if !ok && isBinary(schema) {
1260+
ok = true
1261+
decoder = FileBodyDecoder
1262+
}
1263+
12511264
if !ok {
12521265
return "", nil, &ParseError{
12531266
Kind: KindUnsupportedFormat,

0 commit comments

Comments
 (0)