Skip to content

Commit 5cb9e10

Browse files
committed
Add hack for BackgroundTaskFinishedEvent2.data
1 parent ee8b6ac commit 5cb9e10

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/types.rs

+28-8
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ impl FieldType {
614614
Self::List(field_type) | Self::Set(field_type) => {
615615
format!("List<{}>", field_type.to_csharp_typename()).into()
616616
}
617-
Self::SchemaRef(name) => name.clone().into(),
617+
Self::SchemaRef(name) => filter_schema_ref(name, "Object"),
618618
Self::StringConst(_) => "string".into(),
619619
}
620620
}
@@ -634,7 +634,7 @@ impl FieldType {
634634
Self::List(field_type) | Self::Set(field_type) => {
635635
format!("[]{}", field_type.to_go_typename()).into()
636636
}
637-
Self::SchemaRef(name) => name.clone().into(),
637+
Self::SchemaRef(name) => filter_schema_ref(name, "map[string]any"),
638638
Self::StringConst(_) => "string".into(),
639639
}
640640
}
@@ -655,7 +655,7 @@ impl FieldType {
655655
Self::JsonObject => "Map<String,Any>".into(),
656656
Self::List(field_type) => format!("List<{}>", field_type.to_kotlin_typename()).into(),
657657
Self::Set(field_type) => format!("Set<{}>", field_type.to_kotlin_typename()).into(),
658-
Self::SchemaRef(name) => name.clone().into(),
658+
Self::SchemaRef(name) => filter_schema_ref(name, "Map<String,Any>"),
659659
Self::StringConst(_) => "String".into(),
660660
}
661661
}
@@ -675,7 +675,7 @@ impl FieldType {
675675
Self::Map { value_ty } => {
676676
format!("{{ [key: string]: {} }}", value_ty.to_js_typename()).into()
677677
}
678-
Self::SchemaRef(name) => name.clone().into(),
678+
Self::SchemaRef(name) => filter_schema_ref(name, "any"),
679679
Self::StringConst(_) => "string".into(),
680680
}
681681
}
@@ -702,14 +702,23 @@ impl FieldType {
702702
value_ty.to_rust_typename(),
703703
)
704704
.into(),
705-
Self::SchemaRef(name) => name.clone().into(),
705+
Self::SchemaRef(name) => filter_schema_ref(name, "serde_json::Value"),
706706
Self::StringConst(_) => "String".into()
707707
}
708708
}
709709

710710
pub(crate) fn referenced_schema(&self) -> Option<&str> {
711711
match self {
712-
Self::SchemaRef(v) => Some(v),
712+
Self::SchemaRef(v) => {
713+
// TODO: the `BackgroundTaskFinishedEvent2` struct has a field with type of `Data`
714+
// this corresponds to a `#[serde(untagged)]` enum `svix_server::v1::endpoints::background_tasks::Data`
715+
// we should change this server side, but for now I am changing it here
716+
if v == "Data" {
717+
None
718+
} else {
719+
Some(v)
720+
}
721+
}
713722
Self::List(ty) | Self::Set(ty) | Self::Map { value_ty: ty } => ty.referenced_schema(),
714723
_ => None,
715724
}
@@ -721,7 +730,7 @@ impl FieldType {
721730
Self::Int16 | Self::UInt16 | Self::Int32 | Self::Int64 | Self::UInt64 => "int".into(),
722731
Self::String => "str".into(),
723732
Self::DateTime => "datetime".into(),
724-
Self::SchemaRef(name) => name.clone().into(),
733+
Self::SchemaRef(name) => filter_schema_ref(name, "t.Dict[str, t.Any]"),
725734
Self::Uri => "str".into(),
726735
Self::JsonObject => "t.Dict[str, t.Any]".into(),
727736
Self::Set(field_type) | Self::List(field_type) => {
@@ -752,7 +761,7 @@ impl FieldType {
752761
FieldType::Map { value_ty } => {
753762
format!("Map<String,{}>", value_ty.to_java_typename()).into()
754763
}
755-
FieldType::SchemaRef(name) => name.clone().into(),
764+
FieldType::SchemaRef(name) => filter_schema_ref(name, "Object"),
756765
// backwards compat
757766
FieldType::StringConst(_) => "TypeEnum".into(),
758767
}
@@ -902,3 +911,14 @@ impl serde::Serialize for FieldType {
902911
minijinja::Value::from_object(self.clone()).serialize(serializer)
903912
}
904913
}
914+
915+
fn filter_schema_ref<'a>(name: &'a String, json_obj_typename: &'a str) -> Cow<'a, str> {
916+
// TODO: the `BackgroundTaskFinishedEvent2` struct has a field with type of `Data`
917+
// this corresponds to a `#[serde(untagged)]` enum `svix_server::v1::endpoints::background_tasks::Data`
918+
// we should change this server side, but for now I am changing it here
919+
if name == "Data" {
920+
json_obj_typename.into()
921+
} else {
922+
name.clone().into()
923+
}
924+
}

0 commit comments

Comments
 (0)