@@ -1649,6 +1649,23 @@ func TestDecodeBody(t *testing.T) {
16491649 })
16501650 require .NoError (t , err )
16511651
1652+ multipartBinaryEncodingCT , multipartMimeBinaryEncodingCT , err := newTestMultipartForm ([]* testFormPart {
1653+ {name : "b" , contentType : "application/json" , data : strings .NewReader (`{"bar1": "bar1"}` ), filename : "b1" },
1654+ {name : "d" , contentType : "application/pdf" , data : strings .NewReader ("doo1" ), filename : "d1" },
1655+ {name : "f" , contentType : "application/json" , data : strings .NewReader (`{"foo1": "foo1"}` ), filename : "f1" },
1656+ {name : "f" , contentType : "application/pdf" , data : strings .NewReader ("foo2" ), filename : "f2" },
1657+ })
1658+
1659+ multipartBinaryEncodingCTUnsupported , multipartMimeBinaryEncodingCTUnsupported , err := newTestMultipartForm ([]* testFormPart {
1660+ {name : "b" , contentType : "application/json" , data : strings .NewReader (`{"bar1": "bar1"}` ), filename : "b1" },
1661+ {name : "d" , contentType : "application/pdf" , data : strings .NewReader ("doo1" ), filename : "d1" },
1662+ })
1663+
1664+ multipartBinaryEncodingCTNotMatching , multipartMimeBinaryEncodingCTNotMatching , err := newTestMultipartForm ([]* testFormPart {
1665+ {name : "b" , contentType : "application/json" , data : strings .NewReader (`{"bar1": "bar1"}` ), filename : "b1" },
1666+ {name : "d" , contentType : "application/pdf" , data : strings .NewReader ("doo1" ), filename : "d1" },
1667+ })
1668+
16521669 testCases := []struct {
16531670 name string
16541671 mime string
@@ -1787,6 +1804,65 @@ func TestDecodeBody(t *testing.T) {
17871804 body : strings .NewReader ("foo" ),
17881805 want : "foo" ,
17891806 },
1807+ {
1808+ name : "multipartEncodingCT" ,
1809+ mime : multipartMimeBinaryEncodingCT ,
1810+ body : multipartBinaryEncodingCT ,
1811+ schema : openapi3 .NewObjectSchema ().
1812+ WithProperty ("b" , openapi3 .NewStringSchema ().WithFormat ("binary" )).
1813+ WithProperty ("d" , openapi3 .NewStringSchema ().WithFormat ("binary" )).
1814+ WithProperty ("f" , openapi3 .NewArraySchema ().WithItems (
1815+ openapi3 .NewStringSchema ().WithFormat ("binary" ),
1816+ )),
1817+ want : map [string ]any {"b" : `{"bar1": "bar1"}` , "d" : "doo1" , "f" : []any {`{"foo1": "foo1"}` , "foo2" }},
1818+ },
1819+ {
1820+ name : "multipartEncodingCTUnsupported" ,
1821+ mime : multipartMimeBinaryEncodingCTUnsupported ,
1822+ body : multipartBinaryEncodingCTUnsupported ,
1823+ schema : openapi3 .NewObjectSchema ().
1824+ WithProperty ("b" , openapi3 .NewStringSchema ().WithFormat ("binary" )).
1825+ WithProperty ("d" , openapi3 .NewStringSchema ().WithFormat ("binary" )),
1826+ encoding : map [string ]* openapi3.Encoding {
1827+ "b" : {ContentType : "application/json" },
1828+ "d" : {ContentType : "application/pdf" },
1829+ },
1830+ want : map [string ]any {"b" : map [string ]any {"bar1" : "bar1" }},
1831+ wantErr : & ParseError {
1832+ Kind : KindOther ,
1833+ Cause : & ParseError {
1834+ Kind : KindUnsupportedFormat ,
1835+ Reason : fmt .Sprintf ("%s %q" , prefixUnsupportedCT , "application/pdf" ),
1836+ },
1837+ path : []any {"d" },
1838+ },
1839+ },
1840+ {
1841+ name : "multipartEncodingCTNotMatching" ,
1842+ mime : multipartMimeBinaryEncodingCTNotMatching ,
1843+ body : multipartBinaryEncodingCTNotMatching ,
1844+ schema : openapi3 .NewObjectSchema ().
1845+ WithProperty ("b" , openapi3 .NewStringSchema ().WithFormat ("binary" )).
1846+ WithProperty ("d" , openapi3 .NewStringSchema ().WithFormat ("binary" )),
1847+ encoding : map [string ]* openapi3.Encoding {
1848+ "b" : {ContentType : "application/json" },
1849+ "d" : {ContentType : "application/test" },
1850+ },
1851+ want : map [string ]any {"b" : map [string ]any {"bar1" : "bar1" }},
1852+ wantErr : & ParseError {
1853+ Kind : KindOther ,
1854+ Cause : & ParseError {
1855+ Kind : KindOther ,
1856+ Reason : fmt .Sprintf (
1857+ "%s: header %q, encoding %q" ,
1858+ prefixNotMatchingCT ,
1859+ "application/pdf" ,
1860+ "application/test" ,
1861+ ),
1862+ },
1863+ path : []any {"d" },
1864+ },
1865+ },
17901866 }
17911867 for _ , tc := range testCases {
17921868 t .Run (tc .name , func (t * testing.T ) {
0 commit comments