Skip to content

Commit eb53631

Browse files
woodruffwpsastras
authored andcommitted
fix: bare enums serialize with their tags
1 parent 36b92c5 commit eb53631

File tree

2 files changed

+42
-70
lines changed

2 files changed

+42
-70
lines changed

serde-sarif/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
//! ```
3535
//!
3636
//! Because many of the [sarif::Sarif] structures contain a lot of optional fields, it is
37-
//! often convenient to use the builder pattern to contstruct these structs. Each
37+
//! often convenient to use the builder pattern to construct these structs. Each
3838
//! structure has a builder with a default.
3939
//!
4040
//! ## Example
@@ -57,7 +57,7 @@
5757
//!
5858
//! ## Crate Features
5959
//!
60-
//! This crate contains different features which may be enabled depndending on your
60+
//! This crate contains different features which may be enabled depending on your
6161
//! use case.
6262
//!
6363
//! ### Example

serde-sarif/src/sarif.rs

Lines changed: 40 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ include!(concat!(env!("OUT_DIR"), "/sarif.rs"));
88

99
#[doc = "The SARIF format version of this log file."]
1010
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
11-
#[serde(untagged)]
1211
pub enum Version {
1312
#[strum(serialize = "2.1.0")]
13+
#[serde(rename = "2.1.0")]
1414
V2_1_0,
1515
}
1616

@@ -20,185 +20,141 @@ pub static SCHEMA_URL: &str =
2020

2121
#[doc = "The role or roles played by the artifact in the analysis."]
2222
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
23-
#[serde(untagged)]
23+
#[serde(rename_all = "camelCase")]
24+
#[strum(serialize_all = "camelCase")]
2425
pub enum ArtifactRoles {
25-
#[strum(serialize = "analysisTarget")]
2626
AnalysisTarget,
27-
#[strum(serialize = "attachment")]
2827
Attachment,
29-
#[strum(serialize = "responseFile")]
3028
ResponseFile,
31-
#[strum(serialize = "resultFile")]
3229
ResultFile,
33-
#[strum(serialize = "standardStream")]
3430
StandardStream,
35-
#[strum(serialize = "tracedFile")]
3631
TracedFile,
37-
#[strum(serialize = "unmodified")]
3832
Unmodified,
39-
#[strum(serialize = "modified")]
4033
Modified,
41-
#[strum(serialize = "added")]
4234
Added,
43-
#[strum(serialize = "deleted")]
4435
Deleted,
45-
#[strum(serialize = "renamed")]
4636
Renamed,
47-
#[strum(serialize = "uncontrolled")]
4837
Uncontrolled,
49-
#[strum(serialize = "driver")]
5038
Driver,
51-
#[strum(serialize = "extension")]
5239
Extension,
53-
#[strum(serialize = "translation")]
5440
Translation,
55-
#[strum(serialize = "taxonomy")]
5641
Taxonomy,
57-
#[strum(serialize = "policy")]
5842
Policy,
59-
#[strum(serialize = "referencedOnCommandLine")]
6043
ReferencedOnCommandLine,
61-
#[strum(serialize = "memoryContents")]
6244
MemoryContents,
63-
#[strum(serialize = "directory")]
6445
Directory,
65-
#[strum(serialize = "userSpecifiedConfiguration")]
6646
UserSpecifiedConfiguration,
67-
#[strum(serialize = "toolSpecifiedConfiguration")]
6847
ToolSpecifiedConfiguration,
69-
#[strum(serialize = "debugOutputFile")]
7048
DebugOutputFile,
7149
}
7250

7351
#[doc = "The SARIF format version of this external properties object."]
7452
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
75-
#[serde(untagged)]
7653
pub enum ExternalPropertiesVersion {
7754
#[strum(serialize = "2.1.0")]
55+
#[serde(rename = "2.1.0")]
7856
V2_1_0,
7957
}
8058

8159
#[doc = "A value specifying the severity level of the result."]
8260
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
83-
#[serde(untagged)]
61+
#[serde(rename_all = "camelCase")]
62+
#[strum(serialize_all = "camelCase")]
8463
pub enum NotificationLevel {
85-
#[strum(serialize = "none")]
8664
None,
87-
#[strum(serialize = "note")]
8865
Note,
89-
#[strum(serialize = "warning")]
9066
Warning,
91-
#[strum(serialize = "error")]
9267
Error,
9368
}
9469

9570
#[doc = "Specifies the failure level for the report."]
9671
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
97-
#[serde(untagged)]
72+
#[serde(rename_all = "camelCase")]
73+
#[strum(serialize_all = "camelCase")]
9874
pub enum ReportingConfigurationLevel {
99-
#[strum(serialize = "none")]
10075
None,
101-
#[strum(serialize = "note")]
10276
Note,
103-
#[strum(serialize = "warning")]
10477
Warning,
105-
#[strum(serialize = "error")]
10678
Error,
10779
}
10880

10981
#[doc = "A value that categorizes results by evaluation state."]
11082
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
111-
#[serde(untagged)]
83+
#[serde(rename_all = "camelCase")]
84+
#[strum(serialize_all = "camelCase")]
11285
pub enum ResultKind {
113-
#[strum(serialize = "notApplicable")]
11486
NotApplicable,
115-
#[strum(serialize = "pass")]
11687
Pass,
117-
#[strum(serialize = "fail")]
11888
Fail,
119-
#[strum(serialize = "review")]
12089
Review,
121-
#[strum(serialize = "open")]
12290
Open,
123-
#[strum(serialize = "informational")]
12491
Informational,
12592
}
12693

12794
#[doc = "A value specifying the severity level of the result."]
12895
#[derive(Clone, Copy, Display, Debug, Serialize, Deserialize, EnumString)]
129-
#[serde(untagged)]
96+
#[serde(rename_all = "camelCase")]
97+
#[strum(serialize_all = "camelCase")]
13098
pub enum ResultLevel {
131-
#[strum(serialize = "none")]
13299
None,
133-
#[strum(serialize = "note")]
134100
Note,
135-
#[strum(serialize = "warning")]
136101
Warning,
137-
#[strum(serialize = "error")]
138102
Error,
139103
}
140104

141105
#[doc = "The state of a result relative to a baseline of a previous run."]
142106
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
143-
#[serde(untagged)]
107+
#[serde(rename_all = "camelCase")]
108+
#[strum(serialize_all = "camelCase")]
144109
pub enum ResultBaselineState {
145-
#[strum(serialize = "new")]
146110
New,
147-
#[strum(serialize = "unchanged")]
148111
Unchanged,
149-
#[strum(serialize = "updated")]
150112
Updated,
151-
#[strum(serialize = "absent")]
152113
Absent,
153114
}
154115

155116
#[doc = "Specifies the unit in which the tool measures columns."]
156117
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
157-
#[serde(untagged)]
118+
#[serde(rename_all = "camelCase")]
119+
#[strum(serialize_all = "camelCase")]
158120
pub enum ResultColumnKind {
159-
#[strum(serialize = "utf16CodeUnits")]
160121
Utf16CodeUnits,
161-
#[strum(serialize = "unicodeCodePoints")]
162122
UnicodeCodePoints,
163123
}
164124

165125
#[doc = "A string that indicates where the suppression is persisted."]
166126
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
167-
#[serde(untagged)]
127+
#[serde(rename_all = "camelCase")]
128+
#[strum(serialize_all = "camelCase")]
168129
pub enum SupressionKind {
169-
#[strum(serialize = "inSource")]
170130
InSource,
171-
#[strum(serialize = "external")]
172131
External,
173132
}
174133

175134
#[doc = "A string that indicates the review status of the suppression."]
176135
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
177-
#[serde(untagged)]
136+
#[serde(rename_all = "camelCase")]
137+
#[strum(serialize_all = "camelCase")]
178138
pub enum SupressionStatus {
179-
#[strum(serialize = "accepted")]
180139
Accepted,
181-
#[strum(serialize = "underReview")]
182140
UnderReview,
183141
}
184142

185143
#[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\"."]
186144
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
187-
#[serde(untagged)]
145+
#[serde(rename_all = "camelCase")]
146+
#[strum(serialize_all = "camelCase")]
188147
pub enum ThreadFlowLocationImportance {
189-
#[strum(serialize = "important")]
190148
Important,
191-
#[strum(serialize = "essential")]
192149
Essential,
193150
}
194151

195152
#[doc = "The kinds of data contained in this object."]
196153
#[derive(Display, Debug, Serialize, Deserialize, EnumString)]
197-
#[serde(untagged)]
154+
#[serde(rename_all = "camelCase")]
155+
#[strum(serialize_all = "camelCase")]
198156
pub enum ToolComponentContents {
199-
#[strum(serialize = "localizedData")]
200157
LocalizedData,
201-
#[strum(serialize = "nonLocalizedData")]
202158
NonLocalizedData,
203159
}
204160

@@ -239,6 +195,8 @@ impl From<ToolComponent> for Tool {
239195

240196
#[cfg(test)]
241197
mod tests {
198+
use std::str::FromStr;
199+
242200
use super::*;
243201
macro_rules! map {
244202
($( $key: expr => $val: expr ),*) => {{
@@ -287,4 +245,18 @@ mod tests {
287245
.build();
288246
assert_eq!(property_bag, property_bag_expected);
289247
}
248+
249+
#[test]
250+
fn test_serialize_resultkind() {
251+
assert_eq!(
252+
serde_json::to_string(&ResultKind::Fail).unwrap(),
253+
"\"fail\""
254+
);
255+
}
256+
257+
#[test]
258+
fn test_parse_utf16codeunits() {
259+
let v = ResultColumnKind::from_str("utf16CodeUnits").unwrap();
260+
assert!(matches!(v, ResultColumnKind::Utf16CodeUnits));
261+
}
290262
}

0 commit comments

Comments
 (0)