From a1e9e4ba94dcec000b4fe1b3d34a4adb9b1d5ebf Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Fri, 17 May 2024 23:41:00 +0200 Subject: [PATCH] fix enum type not being wrapped as Vec if repeated --- src/generator/lib/util.py | 9 +++++---- src/generator/templates/api/lib/enum.mako | 4 ++-- src/generator/templates/api/lib/mbuild.mako | 6 ++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/generator/lib/util.py b/src/generator/lib/util.py index d359d73112..e1ba024f52 100644 --- a/src/generator/lib/util.py +++ b/src/generator/lib/util.py @@ -461,10 +461,11 @@ def to_rust_type_inner( return wrap_type(rt) try: if is_property_enum(t): - x = get_enum_type(schema_name, property_name) - return wrap_type(x) - # prefer format if present - rust_type = RUST_TYPE_MAP[t.get("format", t["type"])] + rust_type = get_enum_type(schema_name, property_name) + else: + # prefer format if present + rust_type = RUST_TYPE_MAP[t.get("format", t["type"])] + if rust_type == Vec(None): return wrap_type(Vec(nested_type(t))) if rust_type == HashMap(None, None): diff --git a/src/generator/templates/api/lib/enum.mako b/src/generator/templates/api/lib/enum.mako index f04de43262..bb691172bb 100644 --- a/src/generator/templates/api/lib/enum.mako +++ b/src/generator/templates/api/lib/enum.mako @@ -95,7 +95,7 @@ if not enum_descriptions: <% #print(variant_name, '=>', description) %> % if description: - % for line in e.description.splitlines(): + % for line in description.splitlines(): /// ${line} % endfor /// @@ -138,7 +138,7 @@ impl<'a> Into> for &'a ${enum_type} { % if get_enum_default(e) is not None: impl Default for ${enum_type} { fn default() -> ${enum_type} { - ${enum_type}::${to_enum_variant_name(e.get('default'))} + ${enum_type}::${to_enum_variant_name(e.default)} } } % endif diff --git a/src/generator/templates/api/lib/mbuild.mako b/src/generator/templates/api/lib/mbuild.mako index 6c17d5f7d6..0d19ae9a40 100644 --- a/src/generator/templates/api/lib/mbuild.mako +++ b/src/generator/templates/api/lib/mbuild.mako @@ -581,7 +581,7 @@ match result { % endif ## not is_required_property(p) % endif is_repeated_property(p): % endif ## p.name == 'part' and request_value: - % if p.get('repeated', False): + % if is_repeated_property(p): if ${pname}.len() > 0 { for f in ${pname}.iter() { params.push("${p.name}", ${to_string_impl("f")}); @@ -592,8 +592,10 @@ match result { params.push("${p.name}", ${to_string_impl("value")}); } % else: - params.push("${p.name}", &${to_string_impl(pname)}); + let param = ${to_string_impl(pname)}; + params.push("${p.name}", ¶m); % endif + % endfor params.extend(${paddfields}.iter());