File tree 3 files changed +87
-0
lines changed
packages/openapi-fetch/test
3 files changed +87
-0
lines changed Original file line number Diff line number Diff line change @@ -814,6 +814,46 @@ export interface paths {
814
814
patch ?: never ;
815
815
trace ?: never ;
816
816
} ;
817
+ "/multipart-form-data-file-upload" : {
818
+ parameters : {
819
+ query ?: never ;
820
+ header ?: never ;
821
+ path ?: never ;
822
+ cookie ?: never ;
823
+ } ;
824
+ get ?: never ;
825
+ put ?: never ;
826
+ post : {
827
+ parameters : {
828
+ query ?: never ;
829
+ header ?: never ;
830
+ path ?: never ;
831
+ cookie ?: never ;
832
+ } ;
833
+ requestBody : {
834
+ content : {
835
+ "multipart/form-data" : string ;
836
+ } ;
837
+ } ;
838
+ responses : {
839
+ 200 : {
840
+ headers : {
841
+ [ name : string ] : unknown ;
842
+ } ;
843
+ content : {
844
+ "application/json" : {
845
+ text : string ;
846
+ } ;
847
+ } ;
848
+ } ;
849
+ } ;
850
+ } ;
851
+ delete ?: never ;
852
+ options ?: never ;
853
+ head ?: never ;
854
+ patch ?: never ;
855
+ trace ?: never ;
856
+ } ;
817
857
}
818
858
export type webhooks = Record < string , never > ;
819
859
export interface components {
Original file line number Diff line number Diff line change @@ -470,6 +470,26 @@ paths:
470
470
responses :
471
471
200 :
472
472
$ref : " #/components/responses/MultipleResponse"
473
+ /multipart-form-data-file-upload :
474
+ post :
475
+ requestBody :
476
+ content :
477
+ multipart/form-data :
478
+ schema :
479
+ type : string
480
+ format : binary
481
+ required : true
482
+ responses :
483
+ " 200 " :
484
+ content :
485
+ application/json :
486
+ schema :
487
+ type : object
488
+ properties :
489
+ text :
490
+ type : string
491
+ required :
492
+ - text
473
493
components :
474
494
schemas :
475
495
Post :
Original file line number Diff line number Diff line change @@ -1352,6 +1352,33 @@ describe("client", () => {
1352
1352
customProperty : "value" ,
1353
1353
} ) ;
1354
1354
} ) ;
1355
+
1356
+ it ( 'multipart/form-data with a file' , async ( ) => {
1357
+ const TEST_STRING = 'Hello this is text file string' ;
1358
+
1359
+ const file = new Blob ( [ TEST_STRING ] , { type : 'text/plain' } ) ;
1360
+ const formData = new FormData ( ) ;
1361
+ formData . append ( 'file' , file ) ;
1362
+
1363
+ const client = createClient < paths > ( { baseUrl } ) ;
1364
+ useMockRequestHandler ( {
1365
+ baseUrl,
1366
+ method : "post" ,
1367
+ path : "/multipart-form-data-file-upload" ,
1368
+ handler : async ( data ) => {
1369
+ // Get text from file and send it back
1370
+ const formData = await data . request . formData ( ) ;
1371
+ const text = await ( formData . get ( 'file' ) as File ) . text ( )
1372
+ return new HttpResponse ( JSON . stringify ( { text} ) )
1373
+ } ,
1374
+ } ) ;
1375
+ const { data} = await client . POST ( "/multipart-form-data-file-upload" , {
1376
+ // @ts -ignore // TODO: how to get this to accept FormData?
1377
+ body : formData ,
1378
+ } )
1379
+
1380
+ expect ( data ?. text ) . toBe ( TEST_STRING )
1381
+ } )
1355
1382
} ) ;
1356
1383
1357
1384
describe ( "responses" , ( ) => {
You can’t perform that action at this time.
0 commit comments