#![allow(clippy::derive_partial_eq_without_eq)]
use strum_macros::Display;
use strum_macros::EnumString;
use thiserror::Error;
include!(concat!(env!("OUT_DIR"), "/sarif.rs"));
#[doc = "The SARIF format version of this log file."]
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
#[serde(untagged)]
pub enum Version {
#[strum(serialize = "2.1.0")]
V2_1_0,
}
pub static SCHEMA_URL: &str =
"https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0.json";
#[doc = "The role or roles played by the artifact in the analysis."]
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
#[serde(untagged)]
pub enum ArtifactRoles {
#[strum(serialize = "analysisTarget")]
AnalysisTarget,
#[strum(serialize = "attachment")]
Attachment,
#[strum(serialize = "responseFile")]
ResponseFile,
#[strum(serialize = "resultFile")]
ResultFile,
#[strum(serialize = "standardStream")]
StandardStream,
#[strum(serialize = "tracedFile")]
TracedFile,
#[strum(serialize = "unmodified")]
Unmodified,
#[strum(serialize = "modified")]
Modified,
#[strum(serialize = "added")]
Added,
#[strum(serialize = "deleted")]
Deleted,
#[strum(serialize = "renamed")]
Renamed,
#[strum(serialize = "uncontrolled")]
Uncontrolled,
#[strum(serialize = "driver")]
Driver,
#[strum(serialize = "extension")]
Extension,
#[strum(serialize = "translation")]
Translation,
#[strum(serialize = "taxonomy")]
Taxonomy,
#[strum(serialize = "policy")]
Policy,
#[strum(serialize = "referencedOnCommandLine")]
ReferencedOnCommandLine,
#[strum(serialize = "memoryContents")]
MemoryContents,
#[strum(serialize = "directory")]
Directory,
#[strum(serialize = "userSpecifiedConfiguration")]
UserSpecifiedConfiguration,
#[strum(serialize = "toolSpecifiedConfiguration")]
ToolSpecifiedConfiguration,
#[strum(serialize = "debugOutputFile")]
DebugOutputFile,
}
#[doc = "The SARIF format version of this external properties object."]
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
#[serde(untagged)]
pub enum ExternalPropertiesVersion {
#[strum(serialize = "2.1.0")]
V2_1_0,
}
#[doc = "A value specifying the severity level of the result."]
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
#[serde(untagged)]
pub enum NotificationLevel {
#[strum(serialize = "none")]
None,
#[strum(serialize = "note")]
Note,
#[strum(serialize = "warning")]
Warning,
#[strum(serialize = "error")]
Error,
}
#[doc = "Specifies the failure level for the report."]
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
#[serde(untagged)]
pub enum ReportingConfigurationLevel {
#[strum(serialize = "none")]
None,
#[strum(serialize = "note")]
Note,
#[strum(serialize = "warning")]
Warning,
#[strum(serialize = "error")]
Error,
}
#[doc = "A value that categorizes results by evaluation state."]
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
#[serde(untagged)]
pub enum ResultKind {
#[strum(serialize = "notApplicable")]
NotApplicable,
#[strum(serialize = "pass")]
Pass,
#[strum(serialize = "fail")]
Fail,
#[strum(serialize = "review")]
Review,
#[strum(serialize = "open")]
Open,
#[strum(serialize = "informational")]
Informational,
}
#[doc = "A value specifying the severity level of the result."]
#[derive(Clone, Copy, Display, Debug, Serialize, Deserialize, EnumString)]
#[serde(untagged)]
pub enum ResultLevel {
#[strum(serialize = "none")]
None,
#[strum(serialize = "note")]
Note,
#[strum(serialize = "warning")]
Warning,
#[strum(serialize = "error")]
Error,
}
#[doc = "The state of a result relative to a baseline of a previous run."]
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
#[serde(untagged)]
pub enum ResultBaselineState {
#[strum(serialize = "new")]
New,
#[strum(serialize = "unchanged")]
Unchanged,
#[strum(serialize = "updated")]
Updated,
#[strum(serialize = "absent")]
Absent,
}
#[doc = "Specifies the unit in which the tool measures columns."]
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
#[serde(untagged)]
pub enum ResultColumnKind {
#[strum(serialize = "utf16CodeUnits")]
Utf16CodeUnits,
#[strum(serialize = "unicodeCodePoints")]
UnicodeCodePoints,
}
#[doc = "A string that indicates where the suppression is persisted."]
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
#[serde(untagged)]
pub enum SupressionKind {
#[strum(serialize = "inSource")]
InSource,
#[strum(serialize = "external")]
External,
}
#[doc = "A string that indicates the review status of the suppression."]
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
#[serde(untagged)]
pub enum SupressionStatus {
#[strum(serialize = "accepted")]
Accepted,
#[strum(serialize = "underReview")]
UnderReview,
}
#[doc = "Specifies the importance of this location in understanding the code flow in which it occurs. The order from most to least important is \"essential\", \"important\", \"unimportant\". Default: \"important\"."]
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
#[serde(untagged)]
pub enum ThreadFlowLocationImportance {
#[strum(serialize = "important")]
Important,
#[strum(serialize = "essential")]
Essential,
}
#[doc = "The kinds of data contained in this object."]
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
#[serde(untagged)]
pub enum ToolComponentContents {
#[strum(serialize = "localizedData")]
LocalizedData,
#[strum(serialize = "nonLocalizedData")]
NonLocalizedData,
}
#[derive(Error, Debug)]
pub enum BuilderError {
#[error("uninitialized field: {0}")]
UninitializedField(&'static str),
}
impl From<&String> for MultiformatMessageString {
fn from(message: &String) -> Self {
MultiformatMessageString::builder()
.text(message.clone())
.build()
}
}
impl From<&String> for Message {
fn from(message: &String) -> Self {
Message::builder().text(message.clone()).build()
}
}
impl From<&str> for Message {
fn from(message: &str) -> Self {
Message::builder().text(message).build()
}
}
impl From<ToolComponent> for Tool {
fn from(tool_component: ToolComponent) -> Self {
Tool::builder().driver(tool_component).build()
}
}
#[cfg(test)]
mod tests {
use super::*;
macro_rules! map {
($( $key: expr => $val: expr ),*) => {{
let mut map = ::std::collections::BTreeMap::new();
$( map.insert($key, serde_json::json!($val)); )*
map
}}
}
#[test]
fn test_serialize_property_bag_empty() {
let property_bag = PropertyBag::builder().build();
let json = serde_json::to_string_pretty(&property_bag).unwrap();
let json_expected = r#"{}"#;
assert_eq!(json, json_expected);
}
#[test]
fn test_serialize_property_bag_additional_properties() {
let property_bag = PropertyBag::builder()
.additional_properties(map!["key1".to_string() => "value1"])
.build();
let json = serde_json::to_string_pretty(&property_bag).unwrap();
let json_expected = r#"{
"key1": "value1"
}"#;
assert_eq!(json, json_expected);
}
#[test]
fn test_deserialize_property_bag_empty() {
let json = r#"{}"#;
let property_bag: PropertyBag = serde_json::from_str(json).unwrap();
let property_bag_expected = PropertyBag::builder().build();
assert_eq!(property_bag, property_bag_expected);
}
#[test]
fn test_deserialize_property_bag_additional_properties() {
let json = r#"{
"key1": "value1"
}"#;
let property_bag: PropertyBag = serde_json::from_str(json).unwrap();
let property_bag_expected = PropertyBag::builder()
.additional_properties(map!["key1".to_string() => "value1"])
.build();
assert_eq!(property_bag, property_bag_expected);
}
}