@@ -46,11 +46,14 @@ impl JsonSchemaBuilder {
4646 let mut fields: Vec < _ > = field_path. iter ( ) . map ( |f| f. as_str ( ) ) . collect ( ) ;
4747 fields. reverse ( ) ;
4848 let field_path_str = fields. join ( "." ) ;
49-
49+
5050 // Check if we already have a description for this field
51- if let Some ( existing_description) = self . extra_instructions_per_field . get ( & field_path_str) {
51+ if let Some ( existing_description) =
52+ self . extra_instructions_per_field . get ( & field_path_str)
53+ {
5254 // Concatenate descriptions with newline separator
53- let combined_description = format ! ( "{}\n {}" , existing_description, description. to_string( ) ) ;
55+ let combined_description =
56+ format ! ( "{}\n {}" , existing_description, description. to_string( ) ) ;
5457 self . extra_instructions_per_field
5558 . insert ( field_path_str, combined_description) ;
5659 } else {
@@ -61,7 +64,8 @@ impl JsonSchemaBuilder {
6164 let metadata = schema. metadata . get_or_insert_default ( ) ;
6265 if let Some ( existing_description) = & metadata. description {
6366 // Concatenate descriptions with newline separator
64- let combined_description = format ! ( "{}\n {}" , existing_description, description. to_string( ) ) ;
67+ let combined_description =
68+ format ! ( "{}\n {}" , existing_description, description. to_string( ) ) ;
6569 metadata. description = Some ( combined_description) ;
6670 } else {
6771 metadata. description = Some ( description. to_string ( ) ) ;
@@ -378,25 +382,25 @@ pub fn build_json_schema(
378382#[ cfg( test) ]
379383mod tests {
380384 use super :: * ;
381- use crate :: base:: schema:: { BasicValueType , EnrichedValueType , FieldSchema , StructSchema , ValueType } ;
385+ use crate :: base:: schema:: {
386+ BasicValueType , EnrichedValueType , FieldSchema , StructSchema , ValueType ,
387+ } ;
382388 use std:: sync:: Arc ;
383389
384390 #[ test]
385391 fn test_description_concatenation ( ) {
386392 // Create a struct with a field that has both field-level and type-level descriptions
387393 let struct_schema = StructSchema {
388394 description : Some ( Arc :: from ( "Test struct description" ) ) ,
389- fields : Arc :: new ( vec ! [
390- FieldSchema {
391- name: "uuid_field" . to_string( ) ,
392- value_type: EnrichedValueType {
393- typ: ValueType :: Basic ( BasicValueType :: Uuid ) ,
394- nullable: false ,
395- attrs: Default :: default ( ) ,
396- } ,
397- description: Some ( Arc :: from( "This is a field-level description for UUID" ) ) ,
395+ fields : Arc :: new ( vec ! [ FieldSchema {
396+ name: "uuid_field" . to_string( ) ,
397+ value_type: EnrichedValueType {
398+ typ: ValueType :: Basic ( BasicValueType :: Uuid ) ,
399+ nullable: false ,
400+ attrs: Default :: default ( ) ,
398401 } ,
399- ] ) ,
402+ description: Some ( Arc :: from( "This is a field-level description for UUID" ) ) ,
403+ } ] ) ,
400404 } ;
401405
402406 let enriched_value_type = EnrichedValueType {
@@ -413,21 +417,35 @@ mod tests {
413417 } ;
414418
415419 let result = build_json_schema ( enriched_value_type, options) . unwrap ( ) ;
416-
420+
417421 // Check if the description contains both field and type descriptions
418422 if let Some ( properties) = & result. schema . object {
419423 if let Some ( uuid_field_schema) = properties. properties . get ( "uuid_field" ) {
420424 if let Schema :: Object ( schema_object) = uuid_field_schema {
421- if let Some ( description) = & schema_object. metadata . as_ref ( ) . and_then ( |m| m. description . as_ref ( ) ) {
425+ if let Some ( description) = & schema_object
426+ . metadata
427+ . as_ref ( )
428+ . and_then ( |m| m. description . as_ref ( ) )
429+ {
422430 // Check if both descriptions are present
423- assert ! ( description. contains( "This is a field-level description for UUID" ) ,
424- "Field-level description not found in: {}" , description) ;
425- assert ! ( description. contains( "A UUID, e.g. 123e4567-e89b-12d3-a456-426614174000" ) ,
426- "Type-level description not found in: {}" , description) ;
427-
431+ assert ! (
432+ description. contains( "This is a field-level description for UUID" ) ,
433+ "Field-level description not found in: {}" ,
434+ description
435+ ) ;
436+ assert ! (
437+ description
438+ . contains( "A UUID, e.g. 123e4567-e89b-12d3-a456-426614174000" ) ,
439+ "Type-level description not found in: {}" ,
440+ description
441+ ) ;
442+
428443 // Check that they are separated by a newline
429- assert ! ( description. contains( "\n " ) ,
430- "Descriptions should be separated by newline: {}" , description) ;
444+ assert ! (
445+ description. contains( "\n " ) ,
446+ "Descriptions should be separated by newline: {}" ,
447+ description
448+ ) ;
431449 } else {
432450 panic ! ( "No description found in the schema" ) ;
433451 }
0 commit comments