From e4c4331dc9a150755745dc89028aac047897f1a4 Mon Sep 17 00:00:00 2001 From: DJ Schleen Date: Fri, 13 Sep 2024 16:30:08 +0000 Subject: [PATCH] chore: Add purl field to TrustyResponse struct, do not write null fields to outputs --- src/main.rs | 3 ++- src/models.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index d05ec54..78acfd0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -163,8 +163,9 @@ async fn fetch_purl_bodies( // eprintln!("* Response: {}", body); match serde_json::from_str::(&body) { - Ok(resp) => { + Ok(mut resp) => { //println!("Success: {:?}", resp); + resp.purl = Some(p.to_string()); responses.push(resp); } Err(e) => { diff --git a/src/models.rs b/src/models.rs index a75a27d..022c01e 100644 --- a/src/models.rs +++ b/src/models.rs @@ -11,128 +11,186 @@ // let model: TrustyResponse = serde_json::from_str(&json).unwrap(); // } -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug)] pub struct TrustyResponse { + #[serde(skip_serializing_if = "Option::is_none")] id: Option, + #[serde(skip_serializing_if = "Option::is_none")] status: Option, + #[serde(skip_serializing_if = "Option::is_none")] status_code: Option, + #[serde(skip_serializing_if = "Option::is_none")] name: Option, - #[serde(rename = "type")] + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] ty: Option, + #[serde(skip_serializing_if = "Option::is_none")] version: Option, + #[serde(skip_serializing_if = "Option::is_none")] version_date: Option, + #[serde(skip_serializing_if = "Option::is_none")] author: Option, + #[serde(skip_serializing_if = "Option::is_none")] author_email: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub purl: Option, + + #[serde(skip_serializing_if = "Option::is_none")] package_description: Option, + #[serde(skip_serializing_if = "Option::is_none")] repo_description: Option, + #[serde(skip_serializing_if = "Option::is_none")] origin: Option, + #[serde(skip_serializing_if = "Option::is_none")] stargazers_count: Option, + #[serde(skip_serializing_if = "Option::is_none")] watchers_count: Option, + #[serde(skip_serializing_if = "Option::is_none")] home_page: Option, + #[serde(skip_serializing_if = "Option::is_none")] has_issues: Option, + #[serde(skip_serializing_if = "Option::is_none")] has_projects: Option, + #[serde(skip_serializing_if = "Option::is_none")] has_downloads: Option, + #[serde(skip_serializing_if = "Option::is_none")] forks_count: Option, + #[serde(skip_serializing_if = "Option::is_none")] archived: Option, + #[serde(skip_serializing_if = "Option::is_none")] is_deprecated: Option, + #[serde(skip_serializing_if = "Option::is_none")] disabled: Option, + #[serde(skip_serializing_if = "Option::is_none")] open_issues_count: Option, + #[serde(skip_serializing_if = "Option::is_none")] visibility: Option, + #[serde(skip_serializing_if = "Option::is_none")] default_branch: Option, + #[serde(skip_serializing_if = "Option::is_none")] repository_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] repository_name: Option, + #[serde(skip_serializing_if = "Option::is_none")] contributor_count: Option, + #[serde(skip_serializing_if = "Option::is_none")] public_repos: Option, + #[serde(skip_serializing_if = "Option::is_none")] public_gists: Option, + #[serde(skip_serializing_if = "Option::is_none")] followers: Option, + #[serde(skip_serializing_if = "Option::is_none")] following: Option, + #[serde(skip_serializing_if = "Option::is_none")] owner: Option, + #[serde(skip_serializing_if = "Option::is_none")] contributors: Option>, + #[serde(skip_serializing_if = "Option::is_none")] last_update: Option, + #[serde(skip_serializing_if = "Option::is_none")] scores: Option, + #[serde(skip_serializing_if = "Option::is_none")] malicious: Option, } #[derive(Serialize, Deserialize, Debug)] pub struct Owner { + #[serde(skip_serializing_if = "Option::is_none")] id: Option, + #[serde(skip_serializing_if = "Option::is_none")] author: Option, + #[serde(skip_serializing_if = "Option::is_none")] author_email: Option, + #[serde(skip_serializing_if = "Option::is_none")] login: Option, + #[serde(skip_serializing_if = "Option::is_none")] avatar_url: Option, + #[serde(skip_serializing_if = "Option::is_none")] gravatar_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] url: Option, + #[serde(skip_serializing_if = "Option::is_none")] html_url: Option, + #[serde(skip_serializing_if = "Option::is_none")] company: Option, + #[serde(skip_serializing_if = "Option::is_none")] blog: Option, + #[serde(skip_serializing_if = "Option::is_none")] location: Option, + #[serde(skip_serializing_if = "Option::is_none")] email: Option, + #[serde(skip_serializing_if = "Option::is_none")] hireable: Option, + #[serde(skip_serializing_if = "Option::is_none")] twitter_username: Option, + #[serde(skip_serializing_if = "Option::is_none")] public_repos: Option, + #[serde(skip_serializing_if = "Option::is_none")] public_gists: Option, + #[serde(skip_serializing_if = "Option::is_none")] followers: Option, + #[serde(skip_serializing_if = "Option::is_none")] following: Option, + #[serde(skip_serializing_if = "Option::is_none")] scores: Option, } #[derive(Serialize, Deserialize, Debug)] pub struct Scores { // Add fields here if needed, all wrapped in Option -} \ No newline at end of file +}