Skip to content

Commit 3b8e1d2

Browse files
committed
Use let chains for new bit of code
1 parent a7110ce commit 3b8e1d2

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/main.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use anyhow::{Context as _, bail};
99
use camino::Utf8PathBuf;
1010
use clap::{Parser, Subcommand};
1111
use fs_err::{self as fs};
12+
use schemars::schema::Schema;
1213
use tempfile::TempDir;
1314

1415
mod api;
@@ -205,18 +206,18 @@ fn get_webhooks(spec: &OpenApi) -> Vec<String> {
205206
};
206207

207208
for (_, op) in item.iter() {
208-
let schema_ref = op
209-
.request_body
210-
.as_ref()
211-
.and_then(|v| v.as_item())
212-
.and_then(|v| v.content.get("application/json"))
213-
.and_then(|v| v.schema.as_ref())
214-
.and_then(|v| v.json_schema.clone().into_object().reference)
215-
.and_then(|v| v.split('/').next_back().map(|v| v.to_string()));
216-
if let Some(schema_ref) = schema_ref {
217-
referenced_components.insert(schema_ref);
209+
if let Some(body) = &op.request_body
210+
&& let Some(item) = body.as_item()
211+
&& let Some(json_content) = item.content.get("application/json")
212+
&& let Some(schema) = &json_content.schema
213+
&& let Schema::Object(obj) = &schema.json_schema
214+
&& let Some(reference) = &obj.reference
215+
&& let Some(component_name) = reference.split('/').next_back()
216+
{
217+
referenced_components.insert(component_name.to_owned());
218218
}
219219
}
220220
}
221+
221222
referenced_components.into_iter().collect::<Vec<String>>()
222223
}

0 commit comments

Comments
 (0)