@@ -10,7 +10,7 @@ use indexmap::{IndexMap, IndexSet};
10
10
use openapiv3:: { Components , Parameter , ReferenceOr , Response , StatusCode } ;
11
11
use proc_macro2:: TokenStream ;
12
12
use quote:: { format_ident, quote, ToTokens } ;
13
- use typify:: { TypeId , TypeSpace } ;
13
+ use typify:: { TypeId , TypeSpace , TypeSpacePatch } ;
14
14
15
15
use crate :: {
16
16
template:: PathTemplate ,
@@ -105,7 +105,7 @@ pub struct OperationParameter {
105
105
#[ derive( Debug , Eq , PartialEq ) ]
106
106
pub enum OperationParameterType {
107
107
Type ( TypeId ) ,
108
- Form ( IndexSet < String > ) ,
108
+ Form ( TypeId ) ,
109
109
RawBody ,
110
110
}
111
111
@@ -585,27 +585,15 @@ impl Generator {
585
585
. map ( |param| {
586
586
let name = format_ident ! ( "{}" , param. name) ;
587
587
match & param. typ {
588
- OperationParameterType :: Type ( type_id) => {
588
+ OperationParameterType :: Type ( type_id)
589
+ | OperationParameterType :: Form ( type_id) => {
589
590
let typ = self
590
591
. type_space
591
592
. get_type ( type_id)
592
593
. expect ( "TypeIDs are _never_ deleted. qed" )
593
594
. parameter_ident_with_lifetime ( "a" ) ;
594
595
quote ! { #name: #typ}
595
596
}
596
- OperationParameterType :: Form ( keys) => {
597
- let ts = TokenStream :: from_iter (
598
- itertools:: Itertools :: intersperse (
599
- keys. iter ( ) . map ( |form_prop_name| {
600
- let form_prop_name =
601
- format_ident ! ( "{}" , form_prop_name) ;
602
- quote ! { #form_prop_name: Vec <u8 > }
603
- } ) ,
604
- quote ! { , } ,
605
- ) ,
606
- ) ;
607
- ts
608
- }
609
597
OperationParameterType :: RawBody => {
610
598
quote ! { #name: B }
611
599
}
@@ -935,15 +923,11 @@ impl Generator {
935
923
OperationParameterKind :: Body (
936
924
BodyContentType :: FormData
937
925
) ,
938
- OperationParameterType :: Form ( map ) ,
926
+ OperationParameterType :: Form ( _ ) ,
939
927
) => {
940
- let form_prop_names = map. iter ( ) . cloned ( ) . map ( |form_prop_name| {
941
- let ident= format_ident ! ( "{}" , form_prop_name) ;
942
- quote ! { ( #form_prop_name, #ident) }
943
- } ) ;
944
928
Some ( quote ! {
945
929
// This uses progenitor_client::RequestBuilderExt which sets up a simple form data based on bytes
946
- . form_from_raw( vec! [ # ( #form_prop_names ) , * ] ) ?
930
+ . form_from_raw( body . as_form ( ) ) ?
947
931
} ) } ,
948
932
( OperationParameterKind :: Body ( _) , _) => {
949
933
unreachable ! ( "invalid body kind/type combination" )
@@ -1408,7 +1392,8 @@ impl Generator {
1408
1392
. params
1409
1393
. iter ( )
1410
1394
. map ( |param| match & param. typ {
1411
- OperationParameterType :: Type ( type_id) => {
1395
+ OperationParameterType :: Type ( type_id)
1396
+ | OperationParameterType :: Form ( type_id) => {
1412
1397
let ty = self . type_space . get_type ( type_id) ?;
1413
1398
1414
1399
// For body parameters only, if there's a builder we'll
@@ -1425,10 +1410,6 @@ impl Generator {
1425
1410
}
1426
1411
}
1427
1412
1428
- OperationParameterType :: Form ( _form) => {
1429
- todo ! ( "Form is nit expected here" )
1430
- }
1431
-
1432
1413
OperationParameterType :: RawBody => {
1433
1414
cloneable = false ;
1434
1415
Ok ( quote ! { Result <reqwest:: Body , String > } )
@@ -1441,7 +1422,8 @@ impl Generator {
1441
1422
. params
1442
1423
. iter ( )
1443
1424
. map ( |param| match & param. typ {
1444
- OperationParameterType :: Type ( type_id) => {
1425
+ OperationParameterType :: Type ( type_id)
1426
+ | OperationParameterType :: Form ( type_id) => {
1445
1427
let ty = self . type_space . get_type ( type_id) ?;
1446
1428
let details = ty. details ( ) ;
1447
1429
let optional =
@@ -1460,9 +1442,6 @@ impl Generator {
1460
1442
Ok ( quote ! { Err ( #err_msg. to_string( ) ) } )
1461
1443
}
1462
1444
}
1463
- OperationParameterType :: Form ( _form) => {
1464
- todo ! ( "Form is nit expected here" )
1465
- }
1466
1445
OperationParameterType :: RawBody => {
1467
1446
let err_msg = format ! ( "{} was not initialized" , param. name) ;
1468
1447
Ok ( quote ! { Err ( #err_msg. to_string( ) ) } )
@@ -1474,7 +1453,8 @@ impl Generator {
1474
1453
. params
1475
1454
. iter ( )
1476
1455
. map ( |param| match & param. typ {
1477
- OperationParameterType :: Type ( type_id) => {
1456
+ OperationParameterType :: Type ( type_id)
1457
+ | OperationParameterType :: Form ( type_id) => {
1478
1458
let ty = self . type_space . get_type ( type_id) ?;
1479
1459
if ty. builder ( ) . is_some ( ) {
1480
1460
let type_name = ty. ident ( ) ;
@@ -1488,14 +1468,6 @@ impl Generator {
1488
1468
}
1489
1469
}
1490
1470
1491
- OperationParameterType :: Form ( _form) => {
1492
- todo ! ( "Form is nit expected here" )
1493
- }
1494
-
1495
- OperationParameterType :: Form ( _form) => {
1496
- todo ! ( "Form is nit expected here" )
1497
- }
1498
-
1499
1471
OperationParameterType :: RawBody => Ok ( quote ! { } ) ,
1500
1472
} )
1501
1473
. collect :: < Result < Vec < _ > > > ( ) ?;
@@ -1508,11 +1480,12 @@ impl Generator {
1508
1480
. map ( |param| {
1509
1481
let param_name = format_ident ! ( "{}" , param. name) ;
1510
1482
match & param. typ {
1511
- OperationParameterType :: Type ( type_id) => {
1483
+ OperationParameterType :: Type ( type_id)
1484
+ | OperationParameterType :: Form ( type_id) => {
1512
1485
let ty = self . type_space . get_type ( type_id) ?;
1513
1486
let details = ty. details ( ) ;
1514
1487
match ( & details, ty. builder ( ) ) {
1515
- // TODO right now optional body paramters are not
1488
+ // TODO right now optional body parameters are not
1516
1489
// addressed
1517
1490
( typify:: TypeDetails :: Option ( _) , Some ( _) ) => {
1518
1491
unreachable ! ( )
@@ -1596,7 +1569,7 @@ impl Generator {
1596
1569
}
1597
1570
}
1598
1571
1599
- OperationParameterType :: Form ( form_keys ) => {
1572
+ OperationParameterType :: Form ( type_id ) => {
1600
1573
let err_msg = format ! (
1601
1574
"conversion to `reqwest::Body` for {} failed" ,
1602
1575
param. name,
@@ -2161,7 +2134,19 @@ impl Generator {
2161
2134
schema
2162
2135
) ) ) ,
2163
2136
} ?;
2164
- OperationParameterType :: Form ( mapped)
2137
+
2138
+ let form_name = sanitize (
2139
+ & format ! (
2140
+ "{}-form" ,
2141
+ operation. operation_id. as_ref( ) . unwrap( ) ,
2142
+ ) ,
2143
+ Case :: Pascal ,
2144
+ ) ;
2145
+ let type_id = self
2146
+ . type_space
2147
+ . add_type_with_name ( & schema. to_schema ( ) , Some ( form_name) ) ?;
2148
+ self . forms . insert ( type_id. clone ( ) ) ;
2149
+ OperationParameterType :: Form ( type_id)
2165
2150
}
2166
2151
BodyContentType :: Json | BodyContentType :: FormUrlencoded => {
2167
2152
// TODO it would be legal to have the encoding field set for
0 commit comments