@@ -10,6 +10,84 @@ const {
1010 schemaAllOf
1111} = require ( '../../../examples/options' )
1212
13+ test ( 'support file in json schema' , async t => {
14+ const opts = {
15+ schema : {
16+ consumes : [ 'multipart/form-data' ] ,
17+ body : {
18+ type : 'object' ,
19+ properties : {
20+ file : {
21+ description : 'a file' ,
22+ type : 'string' ,
23+ contentEncoding : 'binary'
24+ }
25+ } ,
26+ required : [ 'file' ]
27+ }
28+ }
29+ }
30+
31+ const fastify = Fastify ( )
32+ await fastify . register ( fastifySwagger , openapiOption )
33+ fastify . post ( '/' , opts , ( ) => { } )
34+
35+ await fastify . ready ( )
36+
37+ const openapiObject = fastify . swagger ( )
38+ const api = await Swagger . validate ( openapiObject )
39+
40+ const definedPath = api . paths [ '/' ] . post
41+ t . assert . ok ( definedPath )
42+ t . assert . deepStrictEqual (
43+ definedPath . requestBody . content [ 'multipart/form-data' ] . schema . properties . file ,
44+ {
45+ description : 'a file' ,
46+ type : 'string' ,
47+ format : 'binary'
48+ }
49+ )
50+ } )
51+
52+ test ( 'support base64 contentEncoding in json schema' , async t => {
53+ const opts = {
54+ schema : {
55+ consumes : [ 'multipart/form-data' ] ,
56+ body : {
57+ type : 'object' ,
58+ properties : {
59+ file : {
60+ description : 'a base64 file' ,
61+ type : 'string' ,
62+ contentEncoding : 'base64'
63+ }
64+ } ,
65+ required : [ 'file' ]
66+ }
67+ }
68+ }
69+
70+ const fastify = Fastify ( )
71+ await fastify . register ( fastifySwagger , openapiOption )
72+ fastify . post ( '/' , opts , ( ) => { } )
73+
74+ await fastify . ready ( )
75+
76+ const openapiObject = fastify . swagger ( )
77+ const api = await Swagger . validate ( openapiObject )
78+
79+ const definedPath = api . paths [ '/' ] . post
80+ t . assert . ok ( definedPath )
81+ t . assert . deepStrictEqual (
82+ definedPath . requestBody . content [ 'multipart/form-data' ] . schema . properties . file ,
83+ {
84+ description : 'a base64 file' ,
85+ type : 'string' ,
86+ format : 'byte'
87+ }
88+ )
89+ } )
90+
1391test ( 'support - oneOf, anyOf, allOf' , async ( t ) => {
1492 t . plan ( 2 )
1593 const fastify = Fastify ( )
0 commit comments