diff --git a/src/lib.rs b/src/lib.rs index 7d7ff24..d759da9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ use okapi::schemars::schema::{InstanceType, Schema, SingleOrVec}; /// Parse OpenAPI 3 schema pub fn parse_schema(file_content: &str) -> OpenApi { - let schema = serde_yaml::from_str::(&file_content).expect("Failed to parse document"); + let schema = serde_yaml::from_str::(file_content).expect("Failed to parse document"); if schema.components.is_none() { log::error!("components is missing!"); @@ -15,7 +15,7 @@ pub fn parse_schema(file_content: &str) -> OpenApi { fn expect_single(e: &SingleOrVec) -> &E { match e { - SingleOrVec::Single(e) => &e, + SingleOrVec::Single(e) => e, SingleOrVec::Vec(v) => &v[0], } } @@ -76,7 +76,7 @@ impl TreeNode { }; TreeNode { - name: other.name.to_string(), + name: self.name.to_string(), r#type, } } @@ -87,7 +87,7 @@ pub fn build_tree(struct_name: &str, components: &Components) -> TreeNode { let schema = components .schemas .get(struct_name) - .expect(&format!("Missing {struct_name}")); + .unwrap_or_else(|| panic!("Missing {struct_name}")); build_tree_schema(schema, struct_name, components) }