@@ -443,21 +443,7 @@ fn struct_to_section_name(struct_name: &str, custom_mappings: &HashMap<String, S
443
443
if let Some ( section_name) = custom_mappings. get ( struct_name) {
444
444
return section_name. clone ( ) ;
445
445
}
446
-
447
- // Convert struct name to section name (e.g., "NodeConfig" -> "[node]")
448
- // NOTE: This function contains hardcoded mappings from Rust struct names to their
449
- // desired TOML section names in the Markdown output. It must be updated if new
450
- // top-level configuration structs are added or existing ones are renamed.
451
- match struct_name {
452
- "BurnchainConfig" => "[burnchain]" . to_string ( ) ,
453
- "NodeConfig" => "[node]" . to_string ( ) ,
454
- "MinerConfig" => "[miner]" . to_string ( ) ,
455
- "ConnectionOptionsFile" => "[connection_options]" . to_string ( ) ,
456
- "FeeEstimationConfigFile" => "[fee_estimation]" . to_string ( ) ,
457
- "EventObserverConfigFile" => "[[events_observer]]" . to_string ( ) ,
458
- "InitialBalanceFile" => "[[ustx_balance]]" . to_string ( ) ,
459
- _ => format ! ( "[{}]" , struct_name. to_lowercase( ) ) ,
460
- }
446
+ format ! ( "[{}]" , struct_name. to_lowercase( ) )
461
447
}
462
448
463
449
fn struct_to_section_name_with_context (
@@ -646,6 +632,11 @@ mod tests {
646
632
let mut struct_to_anchor = HashMap :: new ( ) ;
647
633
let mut field_to_struct = HashMap :: new ( ) ;
648
634
let mut constants = HashMap :: new ( ) ;
635
+ let mut custom_mappings = HashMap :: new ( ) ;
636
+
637
+ // Add custom mappings like the real ones
638
+ custom_mappings. insert ( "NodeConfig" . to_string ( ) , "[node]" . to_string ( ) ) ;
639
+ custom_mappings. insert ( "MinerConfig" . to_string ( ) , "[miner]" . to_string ( ) ) ;
649
640
650
641
// Add some test structs and fields
651
642
struct_to_anchor. insert ( "NodeConfig" . to_string ( ) , "#node" . to_string ( ) ) ;
@@ -667,7 +658,7 @@ mod tests {
667
658
struct_to_anchor,
668
659
field_to_struct,
669
660
constants,
670
- custom_mappings : HashMap :: new ( ) ,
661
+ custom_mappings,
671
662
}
672
663
}
673
664
@@ -676,7 +667,8 @@ mod tests {
676
667
#[ test]
677
668
fn test_generate_markdown_empty_config ( ) {
678
669
let config_docs = create_config_docs ( vec ! [ ] ) ;
679
- let result = generate_markdown ( & config_docs, None , & HashMap :: new ( ) ) . unwrap ( ) ;
670
+ let template_path = "templates/reference_template.md" ;
671
+ let result = generate_markdown ( & config_docs, template_path, & HashMap :: new ( ) ) . unwrap ( ) ;
680
672
681
673
assert ! ( result. contains( "# Stacks Node Configuration Reference" ) ) ;
682
674
assert ! ( result. contains( "## Table of Contents" ) ) ;
@@ -688,7 +680,8 @@ mod tests {
688
680
fn test_generate_markdown_with_one_struct_no_fields ( ) {
689
681
let struct_doc = create_struct_doc ( "TestStruct" , Some ( "A test struct" ) , vec ! [ ] ) ;
690
682
let config_docs = create_config_docs ( vec ! [ struct_doc] ) ;
691
- let result = generate_markdown ( & config_docs, None , & HashMap :: new ( ) ) . unwrap ( ) ;
683
+ let template_path = "templates/reference_template.md" ;
684
+ let result = generate_markdown ( & config_docs, template_path, & HashMap :: new ( ) ) . unwrap ( ) ;
692
685
693
686
assert ! ( result. contains( "# Stacks Node Configuration Reference" ) ) ;
694
687
assert ! ( result. contains( "- [[teststruct]](#teststruct)" ) ) ;
@@ -702,7 +695,8 @@ mod tests {
702
695
let field = create_field_doc ( "test_field" , "A test field" ) ;
703
696
let struct_doc = create_struct_doc ( "TestStruct" , Some ( "A test struct" ) , vec ! [ field] ) ;
704
697
let config_docs = create_config_docs ( vec ! [ struct_doc] ) ;
705
- let result = generate_markdown ( & config_docs, None , & HashMap :: new ( ) ) . unwrap ( ) ;
698
+ let template_path = "templates/reference_template.md" ;
699
+ let result = generate_markdown ( & config_docs, template_path, & HashMap :: new ( ) ) . unwrap ( ) ;
706
700
707
701
assert ! ( result. contains( "# Stacks Node Configuration Reference" ) ) ;
708
702
assert ! ( result. contains( "- [[teststruct]](#teststruct)" ) ) ;
@@ -717,7 +711,28 @@ mod tests {
717
711
718
712
#[ test]
719
713
fn test_struct_to_section_name_known_structs ( ) {
720
- let mappings = HashMap :: new ( ) ;
714
+ let mut mappings = HashMap :: new ( ) ;
715
+ // Load the expected mappings based on section_name_mappings.json
716
+ mappings. insert ( "BurnchainConfig" . to_string ( ) , "[burnchain]" . to_string ( ) ) ;
717
+ mappings. insert ( "NodeConfig" . to_string ( ) , "[node]" . to_string ( ) ) ;
718
+ mappings. insert ( "MinerConfig" . to_string ( ) , "[miner]" . to_string ( ) ) ;
719
+ mappings. insert (
720
+ "ConnectionOptionsFile" . to_string ( ) ,
721
+ "[connection_options]" . to_string ( ) ,
722
+ ) ;
723
+ mappings. insert (
724
+ "FeeEstimationConfigFile" . to_string ( ) ,
725
+ "[fee_estimation]" . to_string ( ) ,
726
+ ) ;
727
+ mappings. insert (
728
+ "EventObserverConfigFile" . to_string ( ) ,
729
+ "[[events_observer]]" . to_string ( ) ,
730
+ ) ;
731
+ mappings. insert (
732
+ "InitialBalanceFile" . to_string ( ) ,
733
+ "[[ustx_balance]]" . to_string ( ) ,
734
+ ) ;
735
+
721
736
assert_eq ! (
722
737
struct_to_section_name( "BurnchainConfig" , & mappings) ,
723
738
"[burnchain]"
0 commit comments