@@ -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,7 @@ 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) | OperationParameterType :: Form ( type_id ) => {
1412
1396
let ty = self . type_space . get_type ( type_id) ?;
1413
1397
1414
1398
// For body parameters only, if there's a builder we'll
@@ -1425,10 +1409,6 @@ impl Generator {
1425
1409
}
1426
1410
}
1427
1411
1428
- OperationParameterType :: Form ( _form) => {
1429
- todo ! ( "Form is nit expected here" )
1430
- }
1431
-
1432
1412
OperationParameterType :: RawBody => {
1433
1413
cloneable = false ;
1434
1414
Ok ( quote ! { Result <reqwest:: Body , String > } )
@@ -1441,7 +1421,7 @@ impl Generator {
1441
1421
. params
1442
1422
. iter ( )
1443
1423
. map ( |param| match & param. typ {
1444
- OperationParameterType :: Type ( type_id) => {
1424
+ OperationParameterType :: Type ( type_id) | OperationParameterType :: Form ( type_id ) => {
1445
1425
let ty = self . type_space . get_type ( type_id) ?;
1446
1426
let details = ty. details ( ) ;
1447
1427
let optional =
@@ -1460,9 +1440,6 @@ impl Generator {
1460
1440
Ok ( quote ! { Err ( #err_msg. to_string( ) ) } )
1461
1441
}
1462
1442
}
1463
- OperationParameterType :: Form ( _form) => {
1464
- todo ! ( "Form is nit expected here" )
1465
- }
1466
1443
OperationParameterType :: RawBody => {
1467
1444
let err_msg = format ! ( "{} was not initialized" , param. name) ;
1468
1445
Ok ( quote ! { Err ( #err_msg. to_string( ) ) } )
@@ -1474,7 +1451,7 @@ impl Generator {
1474
1451
. params
1475
1452
. iter ( )
1476
1453
. map ( |param| match & param. typ {
1477
- OperationParameterType :: Type ( type_id) => {
1454
+ OperationParameterType :: Type ( type_id) | OperationParameterType :: Form ( type_id ) => {
1478
1455
let ty = self . type_space . get_type ( type_id) ?;
1479
1456
if ty. builder ( ) . is_some ( ) {
1480
1457
let type_name = ty. ident ( ) ;
@@ -1488,14 +1465,6 @@ impl Generator {
1488
1465
}
1489
1466
}
1490
1467
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
1468
OperationParameterType :: RawBody => Ok ( quote ! { } ) ,
1500
1469
} )
1501
1470
. collect :: < Result < Vec < _ > > > ( ) ?;
@@ -1508,11 +1477,12 @@ impl Generator {
1508
1477
. map ( |param| {
1509
1478
let param_name = format_ident ! ( "{}" , param. name) ;
1510
1479
match & param. typ {
1511
- OperationParameterType :: Type ( type_id) => {
1480
+ OperationParameterType :: Type ( type_id) |
1481
+ OperationParameterType :: Form ( type_id) => {
1512
1482
let ty = self . type_space . get_type ( type_id) ?;
1513
1483
let details = ty. details ( ) ;
1514
1484
match ( & details, ty. builder ( ) ) {
1515
- // TODO right now optional body paramters are not
1485
+ // TODO right now optional body parameters are not
1516
1486
// addressed
1517
1487
( typify:: TypeDetails :: Option ( _) , Some ( _) ) => {
1518
1488
unreachable ! ( )
@@ -1596,7 +1566,7 @@ impl Generator {
1596
1566
}
1597
1567
}
1598
1568
1599
- OperationParameterType :: Form ( form_keys ) => {
1569
+ OperationParameterType :: Form ( type_id ) => {
1600
1570
let err_msg = format ! (
1601
1571
"conversion to `reqwest::Body` for {} failed" ,
1602
1572
param. name,
@@ -2161,7 +2131,19 @@ impl Generator {
2161
2131
schema
2162
2132
) ) ) ,
2163
2133
} ?;
2164
- OperationParameterType :: Form ( mapped)
2134
+
2135
+ let form_name = sanitize (
2136
+ & format ! (
2137
+ "{}-form" ,
2138
+ operation. operation_id. as_ref( ) . unwrap( ) ,
2139
+ ) ,
2140
+ Case :: Pascal ,
2141
+ ) ;
2142
+ let type_id = self
2143
+ . type_space
2144
+ . add_type_with_name ( & schema. to_schema ( ) , Some ( form_name) ) ?;
2145
+ self . forms . insert ( type_id. clone ( ) ) ;
2146
+ OperationParameterType :: Form ( type_id)
2165
2147
}
2166
2148
BodyContentType :: Json | BodyContentType :: FormUrlencoded => {
2167
2149
// TODO it would be legal to have the encoding field set for
0 commit comments