@@ -79,7 +79,7 @@ fn str_to_snake_case(s: &str) -> String {
7979
8080fn generate_inner_object_name ( object_name : & str , field_name : & str ) -> String {
8181 let camel_field_name = str_to_camel_case ( field_name) ;
82- format ! ( "{}{ }" , object_name , camel_field_name )
82+ format ! ( "{object_name}{camel_field_name }" , )
8383}
8484
8585fn parse_string_enum ( name : & str , schema : & Yaml , output_file : & mut File ) {
@@ -95,7 +95,7 @@ fn parse_string_enum(name: &str, schema: &Yaml, output_file: &mut File) {
9595 "#[derive(Debug, PartialEq, Serialize, Deserialize)]"
9696 )
9797 . unwrap ( ) ;
98- writeln ! ( output_file, "pub enum {} {{" , name ) . unwrap ( ) ;
98+ writeln ! ( output_file, "pub enum {name } {{" , ) . unwrap ( ) ;
9999
100100 for item in enum_items {
101101 writeln ! (
@@ -129,14 +129,9 @@ fn parse_typedef_type(name: &str, schema: &Yaml, output_file: &mut File) {
129129 match type_name {
130130 "string" => {
131131 if let Some ( "map" ) = schema[ "x-oaiTypeLabel" ] . as_str ( ) {
132- writeln ! (
133- output_file,
134- "pub type {} = HashMap<String, String>;\n " ,
135- name
136- )
137- . unwrap ( )
132+ writeln ! ( output_file, "pub type {name} = HashMap<String, String>;\n " , ) . unwrap ( )
138133 } else {
139- writeln ! ( output_file, "pub type {} = String;\n " , name ) . unwrap ( )
134+ writeln ! ( output_file, "pub type {name } = String;\n " , ) . unwrap ( )
140135 }
141136 }
142137 "array" => {
@@ -156,10 +151,10 @@ fn parse_typedef_type(name: &str, schema: &Yaml, output_file: &mut File) {
156151 . unwrap ( )
157152 == "string"
158153 {
159- writeln ! ( output_file, "pub type {} = Vec<String>;\n " , name , ) . unwrap ( ) ;
154+ writeln ! ( output_file, "pub type {name } = Vec<String>;\n " , ) . unwrap ( ) ;
160155 }
161156 }
162- "boolean" => writeln ! ( output_file, "pub type {} = bool;\n " , name ) . unwrap ( ) ,
157+ "boolean" => writeln ! ( output_file, "pub type {name } = bool;\n " , ) . unwrap ( ) ,
163158 _ => unimplemented ! ( "{}" , type_name) ,
164159 }
165160}
@@ -247,15 +242,15 @@ fn parse_object_type(name: &str, schema: &Yaml, output_file: &mut File) {
247242 . get ( & Yaml :: String ( "description" . to_string ( ) ) )
248243 . map ( |x| x. as_str ( ) . unwrap ( ) . trim_end ( ) . replace ( "```" , "***" ) )
249244 {
250- writeln ! ( output_file, "/** {} */" , doc ) . unwrap ( ) ;
245+ writeln ! ( output_file, "/** {doc } */" , ) . unwrap ( ) ;
251246 }
252247
253248 writeln ! (
254249 output_file,
255250 "#[derive(Debug, PartialEq, Serialize, Deserialize)]"
256251 )
257252 . unwrap ( ) ;
258- writeln ! ( output_file, "pub struct {} {{" , name ) . unwrap ( ) ;
253+ writeln ! ( output_file, "pub struct {name } {{" , ) . unwrap ( ) ;
259254
260255 let object_required_list = schema_map
261256 . get ( & Yaml :: String ( "required" . to_string ( ) ) )
@@ -347,24 +342,24 @@ fn parse_object_type(name: &str, schema: &Yaml, output_file: &mut File) {
347342 unimplemented ! ( "{:?} {:?}" , property_name, property_value)
348343 } ;
349344 if field_name == "type" {
350- writeln ! ( output_file, "\t #[serde(rename=\" {}\" )]" , field_name , ) . unwrap ( ) ;
345+ writeln ! ( output_file, "\t #[serde(rename=\" {field_name }\" )]" , ) . unwrap ( ) ;
351346 field_name = "r#type" . to_string ( ) ;
352347 } else if field_name == "static" {
353- writeln ! ( output_file, "\t #[serde(rename=\" {}\" )]" , field_name , ) . unwrap ( ) ;
348+ writeln ! ( output_file, "\t #[serde(rename=\" {field_name }\" )]" , ) . unwrap ( ) ;
354349 field_name = "r#static" . to_string ( ) ;
355350 } else if field_name. contains ( '.' ) {
356- writeln ! ( output_file, "\t #[serde(rename=\" {}\" )]" , field_name , ) . unwrap ( ) ;
351+ writeln ! ( output_file, "\t #[serde(rename=\" {field_name }\" )]" , ) . unwrap ( ) ;
357352 field_name = field_name. replace ( '.' , "_" ) ;
358353 } else if field_name. contains ( "[]" ) {
359- writeln ! ( output_file, "\t #[serde(rename=\" {}\" )]" , field_name , ) . unwrap ( ) ;
354+ writeln ! ( output_file, "\t #[serde(rename=\" {field_name }\" )]" , ) . unwrap ( ) ;
360355 field_name = field_name. replace ( "[]" , "" ) ;
361356 }
362357
363358 if let Some ( doc) = property_hash
364359 . get ( & Yaml :: String ( "description" . to_string ( ) ) )
365360 . map ( |x| x. as_str ( ) . unwrap ( ) . trim_end ( ) . replace ( "```" , "***" ) )
366361 {
367- writeln ! ( output_file, "\t /** {} */" , doc ) . unwrap ( ) ;
362+ writeln ! ( output_file, "\t /** {doc } */" , ) . unwrap ( ) ;
368363 }
369364
370365 let is_nullable = if let Some ( Yaml :: Boolean ( n) ) =
@@ -377,16 +372,15 @@ fn parse_object_type(name: &str, schema: &Yaml, output_file: &mut File) {
377372
378373 if object_required_list. contains ( property_name) && !is_nullable {
379374 if field_name. contains ( [ '-' , '/' ] ) {
380- writeln ! ( output_file, "\t #[serde(rename = \" {}\" )]" , field_name ) . unwrap ( ) ;
375+ writeln ! ( output_file, "\t #[serde(rename = \" {field_name }\" )]" , ) . unwrap ( ) ;
381376 writeln ! (
382377 output_file,
383- "\t pub {}: {}," ,
378+ "\t pub {}: {field_type }," ,
384379 str_to_snake_case( & field_name) ,
385- field_type
386380 )
387381 . unwrap ( ) ;
388382 } else {
389- writeln ! ( output_file, "\t pub {}: {}," , field_name , field_type ) . unwrap ( ) ;
383+ writeln ! ( output_file, "\t pub {field_name }: {field_type }," , ) . unwrap ( ) ;
390384 }
391385 } else {
392386 writeln ! (
@@ -395,16 +389,15 @@ fn parse_object_type(name: &str, schema: &Yaml, output_file: &mut File) {
395389 )
396390 . unwrap ( ) ;
397391 if field_name. contains ( [ '-' , '/' ] ) {
398- writeln ! ( output_file, "\t #[serde(rename = \" {}\" )]" , field_name ) . unwrap ( ) ;
392+ writeln ! ( output_file, "\t #[serde(rename = \" {field_name }\" )]" , ) . unwrap ( ) ;
399393 writeln ! (
400394 output_file,
401- "\t pub {}: Option<{}>," ,
395+ "\t pub {}: Option<{field_type }>," ,
402396 str_to_snake_case( & field_name) ,
403- field_type
404397 )
405398 . unwrap ( ) ;
406399 } else {
407- writeln ! ( output_file, "\t pub {}: Option<{}>," , field_name , field_type ) . unwrap ( ) ;
400+ writeln ! ( output_file, "\t pub {field_name }: Option<{field_type }>," , ) . unwrap ( ) ;
408401 }
409402 }
410403 }
@@ -415,7 +408,7 @@ fn parse_object_type(name: &str, schema: &Yaml, output_file: &mut File) {
415408 . get ( & Yaml :: String ( "description" . to_string ( ) ) )
416409 . map ( |x| x. as_str ( ) . unwrap ( ) . trim_end ( ) . replace ( "```" , "***" ) )
417410 {
418- writeln ! ( output_file, "\t /** {} */" , doc ) . unwrap ( ) ;
411+ writeln ! ( output_file, "\t /** {doc } */" , ) . unwrap ( ) ;
419412 }
420413
421414 writeln ! (
@@ -427,12 +420,12 @@ fn parse_object_type(name: &str, schema: &Yaml, output_file: &mut File) {
427420 let type_label_str = type_label. as_str ( ) . unwrap ( ) ;
428421 match type_label_str {
429422 "map" => {
430- writeln ! ( output_file, "pub struct {}(pub serde_json::Value);\n " , name ) . unwrap ( )
423+ writeln ! ( output_file, "pub struct {name }(pub serde_json::Value);\n " , ) . unwrap ( )
431424 }
432- _ => unimplemented ! ( "{} with type label {:?}" , name , type_label ) ,
425+ _ => unimplemented ! ( "{name } with type label {type_label :?}" , ) ,
433426 }
434427 } else {
435- writeln ! ( output_file, "pub struct {}(pub String);\n " , name ) . unwrap ( ) ;
428+ writeln ! ( output_file, "pub struct {name }(pub String);\n " , ) . unwrap ( ) ;
436429 }
437430 }
438431}
@@ -511,7 +504,7 @@ fn parse_oneof_type(name: &str, schema: &Yaml, output_file: &mut File) {
511504 . get ( & Yaml :: String ( "description" . to_string ( ) ) )
512505 . map ( |x| x. as_str ( ) . unwrap ( ) . trim_end ( ) . replace ( "```" , "***" ) )
513506 {
514- writeln ! ( output_file, "/** {} */" , doc ) . unwrap ( ) ;
507+ writeln ! ( output_file, "/** {doc } */" , ) . unwrap ( ) ;
515508 }
516509
517510 writeln ! (
@@ -520,7 +513,7 @@ fn parse_oneof_type(name: &str, schema: &Yaml, output_file: &mut File) {
520513 )
521514 . unwrap ( ) ;
522515 writeln ! ( output_file, "#[serde(untagged)]" ) . unwrap ( ) ;
523- writeln ! ( output_file, "pub enum {} {{" , name ) . unwrap ( ) ;
516+ writeln ! ( output_file, "pub enum {name } {{" , ) . unwrap ( ) ;
524517
525518 let mut string_enum_already_processed = false ;
526519 for ( index, one_of_variant) in one_of_list. iter ( ) . enumerate ( ) {
@@ -529,12 +522,12 @@ fn parse_oneof_type(name: &str, schema: &Yaml, output_file: &mut File) {
529522 . get ( & Yaml :: String ( "description" . to_string ( ) ) )
530523 . map ( |x| x. as_str ( ) . unwrap ( ) . trim_end ( ) . replace ( "```" , "***" ) )
531524 {
532- writeln ! ( output_file, "\t /** {} */" , doc ) . unwrap ( ) ;
525+ writeln ! ( output_file, "\t /** {doc } */" , ) . unwrap ( ) ;
533526 }
534527
535528 if let Some ( variant_ref) = one_of_variant_hash. get ( & Yaml :: String ( "$ref" . to_string ( ) ) ) {
536529 let variant_name = get_object_name_from_reference ( variant_ref. as_str ( ) . unwrap ( ) ) ;
537- writeln ! ( output_file, "\t {}({})," , variant_name , variant_name ) . unwrap ( ) ;
530+ writeln ! ( output_file, "\t {variant_name }({variant_name })," , ) . unwrap ( ) ;
538531 } else if one_of_variant_hash
539532 . get ( & Yaml :: String ( "$recursiveRef" . to_string ( ) ) )
540533 . is_some ( )
@@ -582,7 +575,7 @@ fn parse_oneof_type(name: &str, schema: &Yaml, output_file: &mut File) {
582575 continue ;
583576 } ;
584577
585- writeln ! ( output_file, "\t {} {{" , variant_title ) . unwrap ( ) ;
578+ writeln ! ( output_file, "\t {variant_title } {{" , ) . unwrap ( ) ;
586579 let schema_properties_map = schema_properties. as_hash ( ) . unwrap ( ) ;
587580 for ( property_name, property_value) in schema_properties_map {
588581 let mut property_name = property_name. as_str ( ) . unwrap ( ) ;
@@ -636,11 +629,11 @@ fn parse_oneof_type(name: &str, schema: &Yaml, output_file: &mut File) {
636629 )
637630 } ;
638631 if property_name == "type" {
639- writeln ! ( output_file, "\t \t #[serde(rename=\" {}\" )]" , property_name )
632+ writeln ! ( output_file, "\t \t #[serde(rename=\" {property_name }\" )]" , )
640633 . unwrap ( ) ;
641634 property_name = "r#type" ;
642635 }
643- writeln ! ( output_file, "\t \t {}: {}," , property_name , property_type ) . unwrap ( ) ;
636+ writeln ! ( output_file, "\t \t {property_name }: {property_type }," , ) . unwrap ( ) ;
644637 }
645638
646639 writeln ! ( output_file, "\t }}," , ) . unwrap ( ) ;
@@ -685,7 +678,7 @@ fn parse_oneof_type(name: &str, schema: &Yaml, output_file: &mut File) {
685678 items_hash. get ( & Yaml :: String ( "$ref" . to_string ( ) ) )
686679 {
687680 let variant_name = get_object_name_from_reference ( item_ref) ;
688- writeln ! ( output_file, "\t ArrayList(Vec<{}>)," , variant_name ) . unwrap ( ) ;
681+ writeln ! ( output_file, "\t ArrayList(Vec<{variant_name }>)," ) . unwrap ( ) ;
689682 } else if items_hash. get ( & Yaml :: String ( "oneOf" . to_string ( ) ) ) . is_some ( ) {
690683 writeln ! (
691684 output_file,
@@ -697,10 +690,10 @@ fn parse_oneof_type(name: &str, schema: &Yaml, output_file: &mut File) {
697690 unimplemented ! ( "{:?}" , items_hash)
698691 }
699692 }
700- _ => panic ! ( "{:?}" , variant_type ) ,
693+ _ => panic ! ( "{variant_type :?}" , ) ,
701694 }
702695 } else {
703- unimplemented ! ( "{:?}" , one_of_variant_hash )
696+ unimplemented ! ( "{one_of_variant_hash :?}" , )
704697 }
705698 }
706699 writeln ! ( output_file, "}}\n " ) . unwrap ( ) ;
@@ -731,23 +724,23 @@ fn parse_allof_type(name: &str, schema: &Yaml, output_file: &mut File) {
731724 . get ( & Yaml :: String ( "description" . to_string ( ) ) )
732725 . map ( |x| x. as_str ( ) . unwrap ( ) . trim_end ( ) . replace ( "```" , "***" ) )
733726 {
734- writeln ! ( output_file, "/** {} */" , doc ) . unwrap ( ) ;
727+ writeln ! ( output_file, "/** {doc } */" , ) . unwrap ( ) ;
735728 }
736729
737730 writeln ! (
738731 output_file,
739732 "#[derive(Debug, PartialEq, Serialize, Deserialize)]"
740733 )
741734 . unwrap ( ) ;
742- writeln ! ( output_file, "pub struct {} {{" , name ) . unwrap ( ) ;
735+ writeln ! ( output_file, "pub struct {name } {{" , ) . unwrap ( ) ;
743736
744737 for all_of_item in all_of_list {
745738 let all_of_item_hash = all_of_item. as_hash ( ) . unwrap ( ) ;
746739 if let Some ( item_ref) = all_of_item_hash. get ( & Yaml :: String ( "$ref" . to_string ( ) ) ) {
747740 let item_name = get_object_name_from_reference ( item_ref. as_str ( ) . unwrap ( ) ) ;
748741 let field_name = camel_to_snake ( item_name) ;
749742 writeln ! ( output_file, "\t #[serde(flatten)]" ) . unwrap ( ) ;
750- writeln ! ( output_file, "\t pub {}: {}," , field_name , item_name ) . unwrap ( ) ;
743+ writeln ! ( output_file, "\t pub {field_name }: {item_name }," , ) . unwrap ( ) ;
751744 } else if let Some ( Yaml :: String ( variant_type) ) =
752745 all_of_item_hash. get ( & Yaml :: String ( "type" . to_string ( ) ) )
753746 {
@@ -814,8 +807,7 @@ fn parse_endpoint_path(path_schema: &Yaml, client_output_file: &mut File) {
814807 let schema_list = path_schema. as_hash ( ) . unwrap ( ) ;
815808
816809 // Before implementing the functions the additional types need to be defined
817- for ( path_name, path_hash) in schema_list {
818- println ! ( "{:?}" , path_name) ;
810+ for ( _, path_hash) in schema_list {
819811 let path_operations = path_hash. as_hash ( ) . unwrap ( ) ;
820812 for ( _, path_operation_hash) in path_operations {
821813 let operation_name =
@@ -1016,7 +1008,6 @@ fn parse_endpoint_path(path_schema: &Yaml, client_output_file: &mut File) {
10161008 writeln ! ( client_output_file, "impl OpenAIClient {{" ) . unwrap ( ) ;
10171009
10181010 for ( path_name, path_hash) in schema_list {
1019- println ! ( "{:?}" , path_name) ;
10201011 let path_operations = path_hash. as_hash ( ) . unwrap ( ) ;
10211012 for ( path_operation_name, path_operation_hash) in path_operations {
10221013 let operation_name =
@@ -1094,14 +1085,13 @@ fn parse_endpoint_path(path_schema: &Yaml, client_output_file: &mut File) {
10941085 } ;
10951086
10961087 if !parameter_required {
1097- parameter_type = format ! ( "Option<{}>" , parameter_type ) ;
1088+ parameter_type = format ! ( "Option<{parameter_type }>" , ) ;
10981089 }
10991090
11001091 write ! (
11011092 client_output_file,
1102- "{}: {}, " ,
1093+ "{}: {parameter_type }, " ,
11031094 parameter[ "name" ] . as_str( ) . unwrap( ) . replace( "[]" , "" ) ,
1104- parameter_type
11051095 )
11061096 . unwrap ( ) ;
11071097 }
@@ -1137,9 +1127,9 @@ fn parse_endpoint_path(path_schema: &Yaml, client_output_file: &mut File) {
11371127 request_body_hash[ "required" ] . as_bool ( ) . unwrap_or ( false ) ;
11381128 write ! ( client_output_file, "request_body: " ) . unwrap ( ) ;
11391129 if request_body_is_required {
1140- write ! ( client_output_file, "{}, " , request_body_type ) . unwrap ( ) ;
1130+ write ! ( client_output_file, "{request_body_type }, " , ) . unwrap ( ) ;
11411131 } else {
1142- write ! ( client_output_file, "Option<{}>, " , request_body_type ) . unwrap ( ) ;
1132+ write ! ( client_output_file, "Option<{request_body_type }>, " , ) . unwrap ( ) ;
11431133 }
11441134 }
11451135
@@ -1396,7 +1386,7 @@ fn parse_endpoint_path(path_schema: &Yaml, client_output_file: &mut File) {
13961386 }
13971387
13981388 writeln ! ( client_output_file, "\t }}\n " , ) . unwrap ( ) ;
1399- println ! ( "\t {:?}" , path_operation_name ) ;
1389+ println ! ( "\t {path_operation_name :?}" , ) ;
14001390 }
14011391 }
14021392
0 commit comments