1use convert_case::{Case, Casing};
6
7pub fn extract_simple_type_name(name: &str) -> String {
12 name.split('.').next_back().unwrap_or(name).to_string()
13}
14
15pub mod strings {
17 use super::*;
18
19 pub fn service_to_handler_name(service_name: &str) -> String {
22 if let Some(base) = service_name.strip_suffix("Service") {
23 format!("{}Handler", base.trim_end_matches('s'))
24 } else {
25 format!("{}Handler", service_name)
26 }
27 }
28
29 pub fn operation_to_method_name(operation_id: &str) -> String {
32 operation_id.to_case(Case::Snake)
33 }
34
35 pub fn service_to_base_path(service_name: &str) -> String {
38 if let Some(base) = service_name.strip_suffix("Service") {
39 base.to_case(Case::Snake)
40 } else {
41 service_name.to_case(Case::Snake)
42 }
43 }
44}
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 mod string_tests {
51 use super::*;
52
53 #[test]
54 fn test_service_to_handler_name() {
55 assert_eq!(
56 strings::service_to_handler_name("CatalogsService"),
57 "CatalogHandler"
58 );
59 assert_eq!(
60 strings::service_to_handler_name("RecipientsService"),
61 "RecipientHandler"
62 );
63 assert_eq!(
64 strings::service_to_handler_name("SchemasService"),
65 "SchemaHandler"
66 );
67 }
68
69 #[test]
70 fn test_operation_to_method_name() {
71 assert_eq!(
72 strings::operation_to_method_name("ListCatalogs"),
73 "list_catalogs"
74 );
75 assert_eq!(
76 strings::operation_to_method_name("CreateCatalog"),
77 "create_catalog"
78 );
79 assert_eq!(
80 strings::operation_to_method_name("GetCatalog"),
81 "get_catalog"
82 );
83 }
84
85 #[test]
86 fn test_service_to_base_path() {
87 assert_eq!(strings::service_to_base_path("CatalogsService"), "catalogs");
88 assert_eq!(
89 strings::service_to_base_path("RecipientsService"),
90 "recipients"
91 );
92 }
93 }
94}