File tree Expand file tree Collapse file tree 2 files changed +10
-18
lines changed
Expand file tree Collapse file tree 2 files changed +10
-18
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ fn main() {
5656
5757 match command {
5858 Cli :: Generate ( args) => {
59- let openapi_specs = parse_openapi_specs ( & args. spec_yaml ) ;
59+ let openapi_specs = parse_openapi_specs ( args. spec_yaml ) . unwrap ( ) ;
6060 gen (
6161 openapi_specs,
6262 & args. output_directory ,
@@ -66,7 +66,7 @@ fn main() {
6666 . unwrap ( ) ;
6767 }
6868 Cli :: Merge ( args) => {
69- let openapi_specs = parse_openapi_specs ( & args. spec_yaml ) ;
69+ let openapi_specs = parse_openapi_specs ( args. spec_yaml ) . unwrap ( ) ;
7070 let openapi =
7171 golem_openapi_client_generator:: merge_all_openapi_specs ( openapi_specs) . unwrap ( ) ;
7272 let file = File :: create ( & args. output_yaml ) . unwrap ( ) ;
@@ -75,15 +75,13 @@ fn main() {
7575 }
7676}
7777
78- fn parse_openapi_specs ( spec : & Vec < PathBuf > ) -> Vec < OpenAPI > {
79- spec. into_iter ( )
80- . map ( |spec| {
81- let file =
82- File :: open ( & spec) . expect ( format ! ( "Could not open file: {:?}" , spec) . as_str ( ) ) ;
78+ fn parse_openapi_specs ( spec : Vec < PathBuf > ) -> Result < Vec < OpenAPI > , Box < dyn std:: error:: Error > > {
79+ spec. iter ( )
80+ . map ( |spec_path| {
81+ let file = File :: open ( spec_path) ?;
8382 let reader = BufReader :: new ( file) ;
84- let openapi: OpenAPI = serde_yaml:: from_reader ( reader)
85- . expect ( format ! ( "Could not deserialize input: {:?}" , spec) . as_str ( ) ) ;
86- openapi
83+ let openapi: OpenAPI = serde_yaml:: from_reader ( reader) ?;
84+ Ok ( openapi)
8785 } )
88- . collect :: < Vec < _ > > ( )
86+ . collect ( )
8987}
Original file line number Diff line number Diff line change @@ -13,13 +13,7 @@ pub fn merge_all_openapi_specs(openapi_specs: Vec<OpenAPI>) -> Result<OpenAPI> {
1313 let mut openapi_specs = openapi_specs;
1414 let first = openapi_specs. pop ( ) . unwrap ( ) ;
1515 let rest = openapi_specs;
16- rest. into_iter ( ) . fold ( Ok ( first) , |acc, open_api| {
17- if let Ok ( acc) = acc {
18- merge_openapi_specs ( acc, open_api)
19- } else {
20- acc
21- }
22- } )
16+ rest. into_iter ( ) . try_fold ( first, merge_openapi_specs)
2317 }
2418}
2519
You can’t perform that action at this time.
0 commit comments