@@ -614,10 +614,8 @@ impl FieldType {
614
614
Self :: List ( field_type) | Self :: Set ( field_type) => {
615
615
format ! ( "List<{}>" , field_type. to_csharp_typename( ) ) . into ( )
616
616
}
617
- Self :: SchemaRef ( name) => name. clone ( ) . into ( ) ,
618
- Self :: StringConst ( _) => {
619
- unreachable ! ( "FieldType::const should never be exposed to template code" )
620
- }
617
+ Self :: SchemaRef ( name) => filter_schema_ref ( name, "Object" ) ,
618
+ Self :: StringConst ( _) => "string" . into ( ) ,
621
619
}
622
620
}
623
621
@@ -636,10 +634,8 @@ impl FieldType {
636
634
Self :: List ( field_type) | Self :: Set ( field_type) => {
637
635
format ! ( "[]{}" , field_type. to_go_typename( ) ) . into ( )
638
636
}
639
- Self :: SchemaRef ( name) => name. clone ( ) . into ( ) ,
640
- Self :: StringConst ( _) => {
641
- unreachable ! ( "FieldType::const should never be exposed to template code" )
642
- }
637
+ Self :: SchemaRef ( name) => filter_schema_ref ( name, "map[string]any" ) ,
638
+ Self :: StringConst ( _) => "string" . into ( ) ,
643
639
}
644
640
}
645
641
@@ -659,10 +655,8 @@ impl FieldType {
659
655
Self :: JsonObject => "Map<String,Any>" . into ( ) ,
660
656
Self :: List ( field_type) => format ! ( "List<{}>" , field_type. to_kotlin_typename( ) ) . into ( ) ,
661
657
Self :: Set ( field_type) => format ! ( "Set<{}>" , field_type. to_kotlin_typename( ) ) . into ( ) ,
662
- Self :: SchemaRef ( name) => name. clone ( ) . into ( ) ,
663
- Self :: StringConst ( _) => {
664
- unreachable ! ( "FieldType::const should never be exposed to template code" )
665
- }
658
+ Self :: SchemaRef ( name) => filter_schema_ref ( name, "Map<String,Any>" ) ,
659
+ Self :: StringConst ( _) => "String" . into ( ) ,
666
660
}
667
661
}
668
662
@@ -681,10 +675,8 @@ impl FieldType {
681
675
Self :: Map { value_ty } => {
682
676
format ! ( "{{ [key: string]: {} }}" , value_ty. to_js_typename( ) ) . into ( )
683
677
}
684
- Self :: SchemaRef ( name) => name. clone ( ) . into ( ) ,
685
- Self :: StringConst ( _) => {
686
- unreachable ! ( "FieldType::const should never be exposed to template code" )
687
- }
678
+ Self :: SchemaRef ( name) => filter_schema_ref ( name, "any" ) ,
679
+ Self :: StringConst ( _) => "string" . into ( ) ,
688
680
}
689
681
}
690
682
@@ -710,14 +702,23 @@ impl FieldType {
710
702
value_ty. to_rust_typename( ) ,
711
703
)
712
704
. into ( ) ,
713
- Self :: SchemaRef ( name) => name . clone ( ) . into ( ) ,
714
- Self :: StringConst ( _) => unreachable ! ( "FieldType::const should never be exposed to template code" ) ,
705
+ Self :: SchemaRef ( name) => filter_schema_ref ( name , "serde_json::Value" ) ,
706
+ Self :: StringConst ( _) => "String" . into ( )
715
707
}
716
708
}
717
709
718
710
pub ( crate ) fn referenced_schema ( & self ) -> Option < & str > {
719
711
match self {
720
- Self :: SchemaRef ( v) => Some ( v) ,
712
+ Self :: SchemaRef ( v) => {
713
+ // TODO(10055): 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
+ }
721
722
Self :: List ( ty) | Self :: Set ( ty) | Self :: Map { value_ty : ty } => ty. referenced_schema ( ) ,
722
723
_ => None ,
723
724
}
@@ -729,7 +730,7 @@ impl FieldType {
729
730
Self :: Int16 | Self :: UInt16 | Self :: Int32 | Self :: Int64 | Self :: UInt64 => "int" . into ( ) ,
730
731
Self :: String => "str" . into ( ) ,
731
732
Self :: DateTime => "datetime" . into ( ) ,
732
- Self :: SchemaRef ( name) => name. clone ( ) . into ( ) ,
733
+ Self :: SchemaRef ( name) => filter_schema_ref ( name, "t.Dict[str, t.Any]" ) ,
733
734
Self :: Uri => "str" . into ( ) ,
734
735
Self :: JsonObject => "t.Dict[str, t.Any]" . into ( ) ,
735
736
Self :: Set ( field_type) | Self :: List ( field_type) => {
@@ -738,9 +739,7 @@ impl FieldType {
738
739
Self :: Map { value_ty } => {
739
740
format ! ( "t.Dict[str, {}]" , value_ty. to_python_typename( ) ) . into ( )
740
741
}
741
- Self :: StringConst ( _) => {
742
- unreachable ! ( "FieldType::const should never be exposed to template code" )
743
- }
742
+ Self :: StringConst ( _) => "str" . into ( ) ,
744
743
}
745
744
}
746
745
@@ -762,10 +761,9 @@ impl FieldType {
762
761
FieldType :: Map { value_ty } => {
763
762
format ! ( "Map<String,{}>" , value_ty. to_java_typename( ) ) . into ( )
764
763
}
765
- FieldType :: SchemaRef ( name) => name. clone ( ) . into ( ) ,
766
- FieldType :: StringConst ( _) => {
767
- unreachable ! ( "FieldType::const should never be exposed to template code" )
768
- }
764
+ FieldType :: SchemaRef ( name) => filter_schema_ref ( name, "Object" ) ,
765
+ // backwards compat
766
+ FieldType :: StringConst ( _) => "TypeEnum" . into ( ) ,
769
767
}
770
768
}
771
769
@@ -853,6 +851,10 @@ impl minijinja::value::Object for FieldType {
853
851
ensure_no_args ( args, "is_json_object" ) ?;
854
852
Ok ( matches ! ( * * self , Self :: JsonObject ) . into ( ) )
855
853
}
854
+ "is_string_const" => {
855
+ ensure_no_args ( args, "is_string_const" ) ?;
856
+ Ok ( matches ! ( * * self , Self :: StringConst ( _) ) . into ( ) )
857
+ }
856
858
857
859
// Returns the inner type of a list or set
858
860
"inner_type" => {
@@ -878,6 +880,14 @@ impl minijinja::value::Object for FieldType {
878
880
} ;
879
881
Ok ( ty. into ( ) )
880
882
}
883
+ "string_const_val" => {
884
+ ensure_no_args ( args, "string_const_val" ) ?;
885
+ let val = match & * * self {
886
+ Self :: StringConst ( val) => Some ( minijinja:: Value :: from_safe_string ( val. clone ( ) ) ) ,
887
+ _ => None ,
888
+ } ;
889
+ Ok ( val. into ( ) )
890
+ }
881
891
_ => Err ( minijinja:: Error :: from ( minijinja:: ErrorKind :: UnknownMethod ) ) ,
882
892
}
883
893
}
@@ -901,3 +911,14 @@ impl serde::Serialize for FieldType {
901
911
minijinja:: Value :: from_object ( self . clone ( ) ) . serialize ( serializer)
902
912
}
903
913
}
914
+
915
+ fn filter_schema_ref < ' a > ( name : & ' a String , json_obj_typename : & ' a str ) -> Cow < ' a , str > {
916
+ // TODO(10055): 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