Fix broken v2 bambulab schema refs, wire up v2 dispatchers, fix PrintJobStatus JSON mismatch
- v2/common/device/device.schema.json: stray backtick in bed $ref broke resolution - v2/report/print/print.schema.json: ams $ref pointed at wrong path (missing ams/ subdir) - v2/common/device/plate.schema.json: $id was copy-pasted from bed.schema.json - Add v2/request.schema.json and v2/report.schema.json dispatchers - v2's leaf schemas were unreachable without them, same oneOf convention as v1 - Rewrite schemas/bambulab/README.md layout section, which still described v1's pre-rename paths and claimed v2 was removed - PrintJob.status serialized as a raw i32 in Rust (prost stores proto3 enums as i32) while ts-types' TypeBox schema validates full enum name strings - add serde with= on the field so Rust JSON matches TS and protobuf's own canonical JSON enum mapping, plus a regression test
This commit is contained in:
@@ -8,6 +8,27 @@ pub use continuum::v1::{
|
||||
MaterialProfile, PrintJob, PrintJobStatus, PrintParameters, Template,
|
||||
};
|
||||
|
||||
// PrintJob.status is generated as a plain i32 (see build.rs's comment) -
|
||||
// (de)serialize it via PrintJobStatus's full proto name strings
|
||||
// (e.g. "PRINT_JOB_STATUS_QUEUED") so Rust's JSON matches ts-types'
|
||||
// TypeBox schema and protobuf's own canonical JSON enum mapping.
|
||||
mod print_job_status_serde {
|
||||
use super::PrintJobStatus;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
pub fn serialize<S: Serializer>(value: &i32, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
let status = PrintJobStatus::try_from(*value).unwrap_or(PrintJobStatus::Unspecified);
|
||||
status.as_str_name().serialize(serializer)
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<i32, D::Error> {
|
||||
let name = String::deserialize(deserializer)?;
|
||||
PrintJobStatus::from_str_name(&name)
|
||||
.map(|status| status as i32)
|
||||
.ok_or_else(|| serde::de::Error::custom(format!("unknown PrintJobStatus: {name}")))
|
||||
}
|
||||
}
|
||||
|
||||
// Bambu's raw MQTT command/report structs are NOT modeled here - they're
|
||||
// plain hand-written Rust + serde in continuum-proxy's
|
||||
// src/printer/bambu_commands/, not proto. That data is JSON-over-MQTT
|
||||
|
||||
Reference in New Issue
Block a user