@@ -1184,7 +1184,10 @@ impl ComponentSchema {
1184
1184
let mut object_schema_reference = SchemaReference :: default ( ) ;
1185
1185
1186
1186
if let Some ( children) = & type_tree. children {
1187
- let children_name = Self :: compose_name ( children) ?;
1187
+ let children_name = Self :: compose_name (
1188
+ Self :: filter_const_generics ( children, container. generics ) ,
1189
+ container. generics ,
1190
+ ) ?;
1188
1191
name_tokens. extend ( quote ! { std:: borrow:: Cow :: Owned ( format!( "{}_{}" , < #rewritten_path as utoipa:: ToSchema >:: name( ) , #children_name) ) } ) ;
1189
1192
} else {
1190
1193
name_tokens. extend (
@@ -1205,7 +1208,8 @@ impl ComponentSchema {
1205
1208
schema_references. extend ( Self :: compose_child_references ( children) ?) ;
1206
1209
1207
1210
let composed_generics =
1208
- Self :: compose_generics ( children) ?. collect :: < Array < _ > > ( ) ;
1211
+ Self :: compose_generics ( children, container. generics ) ?
1212
+ . collect :: < Array < _ > > ( ) ;
1209
1213
quote_spanned ! { type_path. span( ) =>
1210
1214
<#rewritten_path as utoipa:: __dev:: ComposeSchema >:: compose( #composed_generics. to_vec( ) )
1211
1215
}
@@ -1242,8 +1246,11 @@ impl ComponentSchema {
1242
1246
// only set schema references tokens for concrete non generic types
1243
1247
if index. is_none ( ) {
1244
1248
let reference_tokens = if let Some ( children) = & type_tree. children {
1245
- let composed_generics =
1246
- Self :: compose_generics ( children) ?. collect :: < Array < _ > > ( ) ;
1249
+ let composed_generics = Self :: compose_generics (
1250
+ Self :: filter_const_generics ( children, container. generics ) ,
1251
+ container. generics ,
1252
+ ) ?
1253
+ . collect :: < Array < _ > > ( ) ;
1247
1254
quote ! { <#rewritten_path as utoipa:: __dev:: ComposeSchema >:: compose( #composed_generics. to_vec( ) ) }
1248
1255
} else {
1249
1256
quote ! { <#rewritten_path as utoipa:: PartialSchema >:: schema( ) }
@@ -1356,7 +1363,10 @@ impl ComponentSchema {
1356
1363
Ok ( ( ) )
1357
1364
}
1358
1365
1359
- fn compose_name < ' tr , I > ( children : I ) -> Result < TokenStream , Diagnostics >
1366
+ fn compose_name < ' tr , I > (
1367
+ children : I ,
1368
+ generics : & ' tr Generics ,
1369
+ ) -> Result < TokenStream , Diagnostics >
1360
1370
where
1361
1371
I : IntoIterator < Item = & ' tr TypeTree < ' tr > > ,
1362
1372
{
@@ -1365,12 +1375,12 @@ impl ComponentSchema {
1365
1375
. map ( |type_tree| {
1366
1376
let name = type_tree
1367
1377
. path
1368
- . as_ref ( )
1378
+ . as_deref ( )
1369
1379
. expect ( "Generic ValueType::Object must have path" ) ;
1370
- let rewritten_name = name. as_ref ( ) . rewrite_path ( ) ?;
1380
+ let rewritten_name = name. rewrite_path ( ) ?;
1371
1381
1372
1382
if let Some ( children) = & type_tree. children {
1373
- let children_name = Self :: compose_name ( children) ?;
1383
+ let children_name = Self :: compose_name ( Self :: filter_const_generics ( children, generics ) , generics ) ?;
1374
1384
1375
1385
Ok ( quote ! { std:: borrow:: Cow :: Owned ( format!( "{}_{}" , <#rewritten_name as utoipa:: ToSchema >:: name( ) , #children_name) ) } )
1376
1386
} else {
@@ -1384,6 +1394,7 @@ impl ComponentSchema {
1384
1394
1385
1395
fn compose_generics < ' v , I : IntoIterator < Item = & ' v TypeTree < ' v > > > (
1386
1396
children : I ,
1397
+ generics : & ' v Generics ,
1387
1398
) -> Result < impl Iterator < Item = TokenStream > + ' v , Diagnostics >
1388
1399
where
1389
1400
<I as std:: iter:: IntoIterator >:: IntoIter : ' v ,
@@ -1395,7 +1406,7 @@ impl ComponentSchema {
1395
1406
. expect ( "inline TypeTree ValueType::Object must have child path if generic" ) ;
1396
1407
let rewritten_path = path. rewrite_path ( ) ?;
1397
1408
if let Some ( children) = & child. children {
1398
- let items = Self :: compose_generics ( children) ?. collect :: < Array < _ > > ( ) ;
1409
+ let items = Self :: compose_generics ( Self :: filter_const_generics ( children, generics ) , generics ) ?. collect :: < Array < _ > > ( ) ;
1399
1410
Ok ( quote ! { <#rewritten_path as utoipa:: __dev:: ComposeSchema >:: compose( #items. to_vec( ) ) } )
1400
1411
} else {
1401
1412
Ok ( quote ! { <#rewritten_path as utoipa:: PartialSchema >:: schema( ) } )
@@ -1406,6 +1417,31 @@ impl ComponentSchema {
1406
1417
Ok ( iter)
1407
1418
}
1408
1419
1420
+ fn filter_const_generics < ' v , I : IntoIterator < Item = & ' v TypeTree < ' v > > > (
1421
+ children : I ,
1422
+ generics : & ' v Generics ,
1423
+ ) -> impl IntoIterator < Item = & ' v TypeTree < ' v > > + ' v
1424
+ where
1425
+ <I as std:: iter:: IntoIterator >:: IntoIter : ' v ,
1426
+ {
1427
+ children. into_iter ( ) . filter ( |type_tree| {
1428
+ let path = type_tree
1429
+ . path
1430
+ . as_deref ( )
1431
+ . expect ( "child TypeTree must have a Path, did you call this on array or tuple?" ) ;
1432
+ let is_const = path
1433
+ . get_ident ( )
1434
+ . map ( |path_ident| {
1435
+ generics. params . iter ( ) . any (
1436
+ |param| matches ! ( param, GenericParam :: Const ( ty) if ty. ident == * path_ident) ,
1437
+ )
1438
+ } )
1439
+ . unwrap_or ( false ) ;
1440
+
1441
+ !is_const
1442
+ } )
1443
+ }
1444
+
1409
1445
fn compose_child_references < ' a , I : IntoIterator < Item = & ' a TypeTree < ' a > > + ' a > (
1410
1446
children : I ,
1411
1447
) -> Result < impl Iterator < Item = SchemaReference > + ' a , Diagnostics > {
@@ -1416,8 +1452,8 @@ impl ComponentSchema {
1416
1452
} else if type_tree. value_type == ValueType :: Object {
1417
1453
let type_path = type_tree
1418
1454
. path
1419
- . as_ref ( )
1420
- . expect ( "Object TypePath must have type path, compose child references" ) . as_ref ( ) ;
1455
+ . as_deref ( )
1456
+ . expect ( "Object TypePath must have type path, compose child references" ) ;
1421
1457
1422
1458
let rewritten_path = type_path. rewrite_path ( ) ?;
1423
1459
0 commit comments