@@ -1168,7 +1168,7 @@ impl TypeSpace {
11681168 // TODO deal with metadata
11691169 fn convert_number < ' a > (
11701170 & self ,
1171- _metadata : & ' a Option < Box < Metadata > > ,
1171+ metadata : & ' a Option < Box < Metadata > > ,
11721172 _validation : & Option < Box < schemars:: schema:: NumberValidation > > ,
11731173 format : & Option < String > ,
11741174 ) -> Result < ( TypeEntry , & ' a Option < Box < Metadata > > ) > {
@@ -1184,8 +1184,8 @@ impl TypeSpace {
11841184 */
11851185
11861186 match format. as_deref ( ) {
1187- Some ( "float" ) => Ok ( ( TypeEntry :: new_float ( "f32" ) , & None ) ) ,
1188- _ => Ok ( ( TypeEntry :: new_float ( "f64" ) , & None ) ) ,
1187+ Some ( "float" ) => Ok ( ( TypeEntry :: new_float ( "f32" ) , metadata ) ) ,
1188+ _ => Ok ( ( TypeEntry :: new_float ( "f64" ) , metadata ) ) ,
11891189 }
11901190 }
11911191
@@ -2309,4 +2309,83 @@ mod tests {
23092309 let expected = quote ! { not:: a:: real:: library:: Uuid } ;
23102310 assert_eq ! ( actual. to_string( ) , expected. to_string( ) ) ;
23112311 }
2312+
2313+ #[ test]
2314+ fn test_float_type_description ( ) {
2315+ // Test that f64 types preserve their description
2316+ let schema_json = r#"
2317+ {
2318+ "description": "A floating point value",
2319+ "type": "number"
2320+ }
2321+ "# ;
2322+
2323+ let schema: RootSchema = serde_json:: from_str ( schema_json) . unwrap ( ) ;
2324+
2325+ let mut type_space = TypeSpace :: default ( ) ;
2326+ let schema_obj = schemars:: schema:: Schema :: Object ( schema. schema . clone ( ) ) ;
2327+ let ( _, metadata) = type_space
2328+ . convert_schema_object ( Name :: Unknown , & schema_obj, & schema. schema )
2329+ . unwrap ( ) ;
2330+
2331+ // Verify that metadata (including description) is preserved
2332+ assert ! ( metadata. is_some( ) ) ;
2333+ assert_eq ! (
2334+ metadata. as_ref( ) . and_then( |m| m. description. as_deref( ) ) ,
2335+ Some ( "A floating point value" )
2336+ ) ;
2337+ }
2338+
2339+ #[ test]
2340+ fn test_float32_type_description ( ) {
2341+ // Test that f32 types preserve their description
2342+ let schema_json = r#"
2343+ {
2344+ "description": "A 32-bit float",
2345+ "type": "number",
2346+ "format": "float"
2347+ }
2348+ "# ;
2349+
2350+ let schema: RootSchema = serde_json:: from_str ( schema_json) . unwrap ( ) ;
2351+
2352+ let mut type_space = TypeSpace :: default ( ) ;
2353+ let schema_obj = schemars:: schema:: Schema :: Object ( schema. schema . clone ( ) ) ;
2354+ let ( _, metadata) = type_space
2355+ . convert_schema_object ( Name :: Unknown , & schema_obj, & schema. schema )
2356+ . unwrap ( ) ;
2357+
2358+ // Verify that metadata (including description) is preserved
2359+ assert ! ( metadata. is_some( ) ) ;
2360+ assert_eq ! (
2361+ metadata. as_ref( ) . and_then( |m| m. description. as_deref( ) ) ,
2362+ Some ( "A 32-bit float" )
2363+ ) ;
2364+ }
2365+
2366+ #[ test]
2367+ fn test_integer_type_description ( ) {
2368+ // Test that integer types preserve their description (control test)
2369+ let schema_json = r#"
2370+ {
2371+ "description": "An integer value",
2372+ "type": "integer"
2373+ }
2374+ "# ;
2375+
2376+ let schema: RootSchema = serde_json:: from_str ( schema_json) . unwrap ( ) ;
2377+
2378+ let mut type_space = TypeSpace :: default ( ) ;
2379+ let schema_obj = schemars:: schema:: Schema :: Object ( schema. schema . clone ( ) ) ;
2380+ let ( _, metadata) = type_space
2381+ . convert_schema_object ( Name :: Unknown , & schema_obj, & schema. schema )
2382+ . unwrap ( ) ;
2383+
2384+ // Verify that metadata (including description) is preserved
2385+ assert ! ( metadata. is_some( ) ) ;
2386+ assert_eq ! (
2387+ metadata. as_ref( ) . and_then( |m| m. description. as_deref( ) ) ,
2388+ Some ( "An integer value" )
2389+ ) ;
2390+ }
23122391}
0 commit comments