Skip to content

Commit b5da4b0

Browse files
v0.2.4: fix byte[] type, suppress per-variant non_camel_case_types warnings
- parser: map byte[]/Byte[] → Primitive::Bytes and string[]/String[] → Primitive::String so vendor XSD type attributes with Java-style array notation no longer produce invalid Rust (Option<byte[]>) - emitter: emit #[allow(non_camel_case_types)] on each enum variant in addition to the outer enum attribute — ensures rustc and Clippy suppress the "variant should have an UpperCamelCase name" warning regardless of how lint propagation is handled across versions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bb66cab commit b5da4b0

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

crates/spear-gen/src/emitter/rust.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ fn emit_enum(t: &SimpleType, out: &mut String) {
220220
));
221221
continue;
222222
}
223+
out.push_str(" #[allow(non_camel_case_types)]\n");
223224
out.push_str(&format!(" #[serde(rename = \"{}\")]\n", v.name));
224225
out.push_str(&format!(" {} = {},\n", v.name, v.number));
225226
}

crates/spear-gen/src/parser/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ fn resolve_type_ref(raw: &str) -> TypeRef {
402402
"float" => TypeRef::Builtin(Primitive::Float),
403403
"double" | "decimal" => TypeRef::Builtin(Primitive::Double),
404404
"base64Binary" | "hexBinary" => TypeRef::Builtin(Primitive::Bytes),
405+
// Java/.NET-style array notation sometimes found in vendor XSDs
406+
"byte[]" | "Byte[]" => TypeRef::Builtin(Primitive::Bytes),
407+
"string[]" | "String[]" => TypeRef::Builtin(Primitive::String),
405408
other => TypeRef::Named(other.to_owned()),
406409
}
407410
}

crates/spear-gen/tests/fixtures/messages.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,13 @@ mod _codec {
146146
#[derive(prost::Enumeration)]
147147
#[repr(i32)]
148148
pub enum AlertSeverity {
149+
#[allow(non_camel_case_types)]
149150
#[serde(rename = "Info")]
150151
Info = 0,
152+
#[allow(non_camel_case_types)]
151153
#[serde(rename = "Warning")]
152154
Warning = 1,
155+
#[allow(non_camel_case_types)]
153156
#[serde(rename = "Critical")]
154157
Critical = 2,
155158
}
@@ -160,10 +163,13 @@ pub enum AlertSeverity {
160163
#[derive(prost::Enumeration)]
161164
#[repr(i32)]
162165
pub enum AlertType {
166+
#[allow(non_camel_case_types)]
163167
#[serde(rename = "SystemAlert")]
164168
SystemAlert = 0,
169+
#[allow(non_camel_case_types)]
165170
#[serde(rename = "TrackAlert")]
166171
TrackAlert = 1,
172+
#[allow(non_camel_case_types)]
167173
#[serde(rename = "SensorAlert")]
168174
SensorAlert = 2,
169175
}
@@ -217,10 +223,13 @@ pub struct AlertMessage {
217223
#[derive(prost::Enumeration)]
218224
#[repr(i32)]
219225
pub enum RecordMode {
226+
#[allow(non_camel_case_types)]
220227
#[serde(rename = "DATA_RECORD_OFF")]
221228
DATA_RECORD_OFF = 0,
229+
#[allow(non_camel_case_types)]
222230
#[serde(rename = "DATA_RECORD_ON")]
223231
DATA_RECORD_ON = 1,
232+
#[allow(non_camel_case_types)]
224233
#[serde(rename = "DATA_RECORD_PAUSED")]
225234
DATA_RECORD_PAUSED = 2,
226235
}
@@ -231,14 +240,19 @@ pub enum RecordMode {
231240
#[derive(prost::Enumeration)]
232241
#[repr(i32)]
233242
pub enum SystemState {
243+
#[allow(non_camel_case_types)]
234244
#[serde(rename = "Offline")]
235245
Offline = 0,
246+
#[allow(non_camel_case_types)]
236247
#[serde(rename = "Initializing")]
237248
Initializing = 1,
249+
#[allow(non_camel_case_types)]
238250
#[serde(rename = "Operational")]
239251
Operational = 2,
252+
#[allow(non_camel_case_types)]
240253
#[serde(rename = "Degraded")]
241254
Degraded = 3,
255+
#[allow(non_camel_case_types)]
242256
#[serde(rename = "Fault")]
243257
Fault = 4,
244258
}
@@ -312,14 +326,19 @@ pub struct Credentials {
312326
#[derive(prost::Enumeration)]
313327
#[repr(i32)]
314328
pub enum TrackCategory {
329+
#[allow(non_camel_case_types)]
315330
#[serde(rename = "Unknown")]
316331
Unknown = 0,
332+
#[allow(non_camel_case_types)]
317333
#[serde(rename = "Air")]
318334
Air = 1,
335+
#[allow(non_camel_case_types)]
319336
#[serde(rename = "Surface")]
320337
Surface = 2,
338+
#[allow(non_camel_case_types)]
321339
#[serde(rename = "Subsurface")]
322340
Subsurface = 3,
341+
#[allow(non_camel_case_types)]
323342
#[serde(rename = "Land")]
324343
Land = 4,
325344
}
@@ -330,12 +349,16 @@ pub enum TrackCategory {
330349
#[derive(prost::Enumeration)]
331350
#[repr(i32)]
332351
pub enum TrackQuality {
352+
#[allow(non_camel_case_types)]
333353
#[serde(rename = "Poor")]
334354
Poor = 0,
355+
#[allow(non_camel_case_types)]
335356
#[serde(rename = "Fair")]
336357
Fair = 1,
358+
#[allow(non_camel_case_types)]
337359
#[serde(rename = "Good")]
338360
Good = 2,
361+
#[allow(non_camel_case_types)]
339362
#[serde(rename = "Excellent")]
340363
Excellent = 3,
341364
}

0 commit comments

Comments
 (0)