use crate::types::{Message, MultiformatMessage, NotificationLevel};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Tool {
pub driver: ToolComponent,
pub extensions: Option<Vec<ToolComponent>>,
#[serde(flatten)]
pub properties: Option<HashMap<String, serde_json::Value>>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ToolComponent {
pub guid: Option<String>,
pub name: String,
pub organization: Option<String>,
pub product: Option<String>,
pub product_suite: Option<String>,
pub short_description: Option<MultiformatMessage>,
pub full_description: Option<MultiformatMessage>,
pub full_name: Option<String>,
pub version: Option<String>,
pub semantic_version: Option<String>,
pub dotted_quad_file_version: Option<String>,
pub release_date_utc: Option<String>,
pub download_uri: Option<String>,
pub information_uri: Option<String>,
pub global_message_strings: Option<HashMap<String, MultiformatMessage>>,
pub notifications: Option<Vec<ReportingDescriptor>>,
pub rules: Option<Vec<ReportingDescriptor>>,
pub taxa: Option<Vec<ReportingDescriptor>>,
pub locations: Option<Vec<crate::types::ArtifactLocation>>,
pub language: Option<String>,
pub contents: Option<Vec<ToolComponentContents>>,
pub is_comprehensive: Option<bool>,
pub localized_data_semantic_version: Option<String>,
pub minimum_required_localized_data_semantic_version: Option<String>,
pub associated_component: Option<ToolComponentReference>,
pub translation_metadata: Option<TranslationMetadata>,
pub supported_taxonomies: Option<Vec<ToolComponentReference>>,
#[serde(flatten)]
pub properties: Option<HashMap<String, serde_json::Value>>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportingDescriptor {
pub id: String,
pub deprecated_ids: Option<Vec<String>>,
pub guid: Option<String>,
pub deprecated_guids: Option<Vec<String>>,
pub name: Option<String>,
pub deprecated_names: Option<Vec<String>>,
pub short_description: Option<MultiformatMessage>,
pub full_description: Option<MultiformatMessage>,
pub message_strings: Option<HashMap<String, MultiformatMessage>>,
pub default_configuration: Option<ReportingConfiguration>,
pub help_uri: Option<String>,
pub help: Option<MultiformatMessage>,
pub relationships: Option<Vec<ReportingDescriptorRelationship>>,
#[serde(flatten)]
pub properties: Option<HashMap<String, serde_json::Value>>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportingConfiguration {
pub enabled: Option<bool>,
pub level: Option<NotificationLevel>,
pub parameters: Option<HashMap<String, serde_json::Value>>,
#[serde(flatten)]
pub properties: Option<HashMap<String, serde_json::Value>>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportingDescriptorRelationship {
pub target: ReportingDescriptorReference,
pub kinds: Option<Vec<String>>,
pub description: Option<Message>,
#[serde(flatten)]
pub properties: Option<HashMap<String, serde_json::Value>>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportingDescriptorReference {
pub id: Option<String>,
pub index: Option<i32>,
pub guid: Option<String>,
pub tool_component: Option<ToolComponentReference>,
#[serde(flatten)]
pub properties: Option<HashMap<String, serde_json::Value>>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ToolComponentReference {
pub name: Option<String>,
pub index: Option<i32>,
pub guid: Option<String>,
#[serde(flatten)]
pub properties: Option<HashMap<String, serde_json::Value>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum ToolComponentContents {
LocalizedData,
NonLocalizedData,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TranslationMetadata {
pub name: String,
pub full_name: Option<String>,
pub short_description: Option<MultiformatMessage>,
pub full_description: Option<MultiformatMessage>,
pub download_uri: Option<String>,
pub information_uri: Option<String>,
#[serde(flatten)]
pub properties: Option<HashMap<String, serde_json::Value>>,
}
impl Tool {
pub fn new(name: impl Into<String>) -> Self {
Self {
driver: ToolComponent::new(name),
extensions: None,
properties: None,
}
}
pub fn add_extension(mut self, extension: ToolComponent) -> Self {
self.extensions.get_or_insert_with(Vec::new).push(extension);
self
}
}
impl ToolComponent {
pub fn new(name: impl Into<String>) -> Self {
Self {
guid: None,
name: name.into(),
organization: None,
product: None,
product_suite: None,
short_description: None,
full_description: None,
full_name: None,
version: None,
semantic_version: None,
dotted_quad_file_version: None,
release_date_utc: None,
download_uri: None,
information_uri: None,
global_message_strings: None,
notifications: None,
rules: None,
taxa: None,
locations: None,
language: None,
contents: None,
is_comprehensive: None,
localized_data_semantic_version: None,
minimum_required_localized_data_semantic_version: None,
associated_component: None,
translation_metadata: None,
supported_taxonomies: None,
properties: None,
}
}
pub fn with_version(mut self, version: impl Into<String>) -> Self {
self.version = Some(version.into());
self
}
pub fn with_organization(mut self, organization: impl Into<String>) -> Self {
self.organization = Some(organization.into());
self
}
pub fn add_rule(mut self, rule: ReportingDescriptor) -> Self {
self.rules.get_or_insert_with(Vec::new).push(rule);
self
}
pub fn with_information_uri(mut self, uri: impl Into<String>) -> Self {
self.information_uri = Some(uri.into());
self
}
}
impl ReportingDescriptor {
pub fn new(id: impl Into<String>) -> Self {
Self {
id: id.into(),
deprecated_ids: None,
guid: None,
deprecated_guids: None,
name: None,
deprecated_names: None,
short_description: None,
full_description: None,
message_strings: None,
default_configuration: None,
help_uri: None,
help: None,
relationships: None,
properties: None,
}
}
pub fn with_name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}
pub fn with_short_description(mut self, description: impl Into<MultiformatMessage>) -> Self {
self.short_description = Some(description.into());
self
}
pub fn with_help_uri(mut self, uri: impl Into<String>) -> Self {
self.help_uri = Some(uri.into());
self
}
}