From f1d1ec7bcaaa72251efd9b989268591a68ec3bd9 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Tue, 31 Mar 2026 23:03:54 -0400 Subject: [PATCH] Fix type for ThreadFlowLocation::importance Signed-off-by: William Woodruff --- serde-sarif/build.rs | 14 ++++++++++++++ serde-sarif/src/sarif.rs | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/serde-sarif/build.rs b/serde-sarif/build.rs index a7e522ee..4e150cd7 100644 --- a/serde-sarif/build.rs +++ b/serde-sarif/build.rs @@ -110,6 +110,20 @@ fn process_token_stream(input: proc_macro2::TokenStream) -> syn::File { } } + // Rewrite ThreadFlowLocation::importance to use ThreadFlowLocationImportance + // instead of serde_json::Value. + // This is a workaround for schemafy's inability to produce appropriate + // exhaustive enums here. + if s.ident == "ThreadFlowLocation" { + if let syn::Fields::Named(fields) = &mut s.fields { + for field in fields.named.iter_mut() { + if field.ident.as_ref().unwrap() == "importance" { + field.ty = syn::parse_quote! { Option }; + } + } + } + } + // for each struct field, if that field is Optional, set None // as the default value when using the builder (&mut s.fields).into_iter().for_each(|ref mut field| { diff --git a/serde-sarif/src/sarif.rs b/serde-sarif/src/sarif.rs index d6f267b8..d1f54efe 100644 --- a/serde-sarif/src/sarif.rs +++ b/serde-sarif/src/sarif.rs @@ -145,7 +145,9 @@ pub enum SupressionStatus { } #[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)] +#[derive( + Clone, Display, Debug, Serialize, Deserialize, EnumString, PartialEq, +)] #[serde(rename_all = "camelCase")] #[strum(serialize_all = "camelCase")] pub enum ThreadFlowLocationImportance {