Skip to content

Commit 2e6d3cb

Browse files
committed
java: All string const are called TypeEnum
This is what the old openapi-generator did
1 parent 46532d3 commit 2e6d3cb

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/types.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,17 @@ impl FieldType {
752752
FieldType::Map { value_ty } => {
753753
format!("Map<String,{}>", value_ty.to_java_typename()).into()
754754
}
755-
FieldType::SchemaRef(name) => name.clone().into(),
756-
FieldType::StringConst(_) => "String".into(),
755+
FieldType::SchemaRef(name) => {
756+
// TODO(mendy): this corresponds to a `#[serde(untagged)]` enum `svix_server::v1::endpoints::background_tasks::Data`
757+
// we should change this server side
758+
if name == "Data" {
759+
"Object".into()
760+
} else {
761+
name.clone().into()
762+
}
763+
}
764+
// backwards compat
765+
FieldType::StringConst(_) => "TypeEnum".into(),
757766
}
758767
}
759768

@@ -841,6 +850,10 @@ impl minijinja::value::Object for FieldType {
841850
ensure_no_args(args, "is_json_object")?;
842851
Ok(matches!(**self, Self::JsonObject).into())
843852
}
853+
"is_string_const" => {
854+
ensure_no_args(args, "is_string_const")?;
855+
Ok(matches!(**self, Self::StringConst(_)).into())
856+
}
844857

845858
// Returns the inner type of a list or set
846859
"inner_type" => {
@@ -866,6 +879,14 @@ impl minijinja::value::Object for FieldType {
866879
};
867880
Ok(ty.into())
868881
}
882+
"string_const_val" => {
883+
ensure_no_args(args, "value_type")?;
884+
let val = match &**self {
885+
Self::StringConst(val) => Some(minijinja::Value::from_safe_string(val.clone())),
886+
_ => None,
887+
};
888+
Ok(val.into())
889+
}
869890
_ => Err(minijinja::Error::from(minijinja::ErrorKind::UnknownMethod)),
870891
}
871892
}

0 commit comments

Comments
 (0)