@@ -907,13 +907,23 @@ mod tests {
907907 #[ test]
908908 fn test_is_known_type_empty_segments ( ) {
909909 // Test line 209: empty path segments returns false
910- // Note: It's hard to create a Type::Path with empty segments via parse,
911- // but we can test the normal path behavior and document the edge case
910+ // Create a Type::Path programmatically with empty segments
911+ use syn:: punctuated:: Punctuated ;
912+
912913 let known_schemas = HashMap :: new ( ) ;
913914 let struct_definitions = HashMap :: new ( ) ;
914915
915- // Non-path type returns false (line 209 is for empty segments which is rare)
916- let ty: Type = syn:: parse_str ( "&str" ) . unwrap ( ) ;
916+ // Create Type::Path with empty segments
917+ let type_path = syn:: TypePath {
918+ qself : None ,
919+ path : syn:: Path {
920+ leading_colon : None ,
921+ segments : Punctuated :: new ( ) , // Empty segments!
922+ } ,
923+ } ;
924+ let ty = Type :: Path ( type_path) ;
925+
926+ // This MUST hit line 209 because path.segments.is_empty() is true
917927 assert ! ( !is_known_type( & ty, & known_schemas, & struct_definitions) ) ;
918928 }
919929
@@ -937,15 +947,28 @@ mod tests {
937947 #[ test]
938948 fn test_parse_query_struct_empty_path_segments ( ) {
939949 // Test line 245: empty path segments in parse_query_struct_to_parameters
940- // This is the early return when path.segments.is_empty()
950+ // Create a Type::Path programmatically with empty segments
951+ use syn:: punctuated:: Punctuated ;
952+
941953 let known_schemas = HashMap :: new ( ) ;
942954 let struct_definitions = HashMap :: new ( ) ;
943955
944- // A reference type (not a path type) should return None
945- let ty: Type = syn:: parse_str ( "&QueryParams" ) . unwrap ( ) ;
956+ // Create Type::Path with empty segments
957+ let type_path = syn:: TypePath {
958+ qself : None ,
959+ path : syn:: Path {
960+ leading_colon : None ,
961+ segments : Punctuated :: new ( ) , // Empty segments!
962+ } ,
963+ } ;
964+ let ty = Type :: Path ( type_path) ;
965+
966+ // This MUST hit line 245 because path.segments.is_empty() is true
946967 let result = parse_query_struct_to_parameters ( & ty, & known_schemas, & struct_definitions) ;
947- // Line 242 matches Type::Path, but &QueryParams is Type::Reference
948- assert ! ( result. is_none( ) ) ;
968+ assert ! (
969+ result. is_none( ) ,
970+ "Empty path segments should return None (line 245)"
971+ ) ;
949972 }
950973
951974 #[ test]
@@ -988,6 +1011,23 @@ mod tests {
9881011 }
9891012 }
9901013
1014+ // NOTE: Line 313 is defensive/unreachable code.
1015+ //
1016+ // Analysis: Line 313 requires:
1017+ // 1. is_optional == true (field type starts with "Option")
1018+ // 2. field_schema is still SchemaRef::Ref after the conversion at lines 294-304
1019+ //
1020+ // However, parse_type_to_schema_ref_with_schemas("Option<T>") ALWAYS returns
1021+ // SchemaRef::Inline because:
1022+ // - schema.rs lines 650-668 handle Option specially
1023+ // - If inner type is Inline → returns Inline (line 660)
1024+ // - If inner type is Ref → wraps in Inline (line 664)
1025+ //
1026+ // Therefore, for any field whose type starts with "Option", field_schema at line 290
1027+ // will always be SchemaRef::Inline, making the else branch at line 312-313 unreachable.
1028+ //
1029+ // This is defensive code guarding against future changes to Option handling in schema.rs.
1030+
9911031 #[ test]
9921032 fn test_schema_ref_to_inline_conversion_required ( ) {
9931033 // Test line 318: SchemaRef::Ref converted to inline for required fields
0 commit comments