Skip to content

Commit 53ee92d

Browse files
committed
Implement custom JsonSchema
1 parent 94ae9d6 commit 53ee92d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

modeling-cmds/src/shared.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use enum_iterator::Sequence;
22
use parse_display_derive::{Display, FromStr};
3-
use schemars::JsonSchema;
3+
use schemars::{schema::SchemaObject, JsonSchema};
44
use serde::{Deserialize, Serialize};
55
use uuid::Uuid;
66

@@ -966,10 +966,9 @@ mod tests {
966966
}
967967

968968
/// How a property of an object should be transformed.
969-
#[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize)]
969+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
970970
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
971971
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
972-
#[serde(rename = "TransformBy")]
973972
pub struct TransformBy<T> {
974973
/// The scale, or rotation, or translation.
975974
pub property: T,
@@ -983,6 +982,24 @@ pub struct TransformBy<T> {
983982
pub is_local: bool,
984983
}
985984

985+
impl<T: JsonSchema> JsonSchema for TransformBy<T> {
986+
fn schema_name() -> String {
987+
format!("TransformByFor{}", T::schema_name())
988+
}
989+
990+
fn schema_id() -> std::borrow::Cow<'static, str> {
991+
std::borrow::Cow::Owned(format!("{}::TransformBy<{}>", module_path!(), T::schema_id()))
992+
}
993+
994+
fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
995+
SchemaObject {
996+
instance_type: Some(schemars::schema::InstanceType::String.into()),
997+
..Default::default()
998+
}
999+
.into()
1000+
}
1001+
}
1002+
9861003
/// Container that holds a translate, rotate and scale.
9871004
#[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize)]
9881005
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

0 commit comments

Comments
 (0)