From 9226f3c646b5de4d73bc3563a7b64282305b2bc5 Mon Sep 17 00:00:00 2001 From: Eddy Filip Date: Wed, 26 Feb 2025 17:13:07 +0100 Subject: [PATCH 1/2] Fix writing enum values in Go For Algebraic Rust Enums, when generating them in Go, the values of the constants were the original name of the enum variant instead of the renamed one, which takes into consideration the serde attributes. Because of that, it could happen that in such enums the unmarshaling of JSON will fail due to not having any content to process. That was caused by the match case not hitting any variant. --- core/src/language/go.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/language/go.rs b/core/src/language/go.rs index c86de136..18c27443 100644 --- a/core/src/language/go.rs +++ b/core/src/language/go.rs @@ -413,7 +413,7 @@ impl Go { "\t{} {} = {:?}", variant_type_const, variant_key_type, - &v.shared().id.original + &v.shared().id.renamed )?; } From de99fa738fdf30dbf48ef8aa97994a7689a43bbe Mon Sep 17 00:00:00 2001 From: Eddy Filip Date: Wed, 26 Feb 2025 17:19:49 +0100 Subject: [PATCH 2/2] update-tests --- .../tests/anonymous_struct_with_rename/output.go | 6 +++--- .../data/tests/can_generate_algebraic_enum/output.go | 8 ++++---- core/data/tests/can_handle_unit_type/output.go | 2 +- core/data/tests/recursive_enum_decorator/output.go | 12 ++++++------ .../test_algebraic_enum_case_name_support/output.go | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/data/tests/anonymous_struct_with_rename/output.go b/core/data/tests/anonymous_struct_with_rename/output.go index ae3a5132..d5d7a853 100644 --- a/core/data/tests/anonymous_struct_with_rename/output.go +++ b/core/data/tests/anonymous_struct_with_rename/output.go @@ -20,9 +20,9 @@ type AnonymousStructWithRenameKebabCaseInner struct { } type AnonymousStructWithRenameTypes string const ( - AnonymousStructWithRenameTypeVariantList AnonymousStructWithRenameTypes = "List" - AnonymousStructWithRenameTypeVariantLongFieldNames AnonymousStructWithRenameTypes = "LongFieldNames" - AnonymousStructWithRenameTypeVariantKebabCase AnonymousStructWithRenameTypes = "KebabCase" + AnonymousStructWithRenameTypeVariantList AnonymousStructWithRenameTypes = "list" + AnonymousStructWithRenameTypeVariantLongFieldNames AnonymousStructWithRenameTypes = "longFieldNames" + AnonymousStructWithRenameTypeVariantKebabCase AnonymousStructWithRenameTypes = "kebabCase" ) type AnonymousStructWithRename struct{ Type AnonymousStructWithRenameTypes `json:"type"` diff --git a/core/data/tests/can_generate_algebraic_enum/output.go b/core/data/tests/can_generate_algebraic_enum/output.go index d32fb915..1f9f9e4f 100644 --- a/core/data/tests/can_generate_algebraic_enum/output.go +++ b/core/data/tests/can_generate_algebraic_enum/output.go @@ -121,11 +121,11 @@ func NewAdvancedColorsTypeVariantReallyCoolType(content *ItemDetailsFieldValue) type AdvancedColors2Types string const ( // This is a case comment - AdvancedColors2TypeVariantString AdvancedColors2Types = "String" - AdvancedColors2TypeVariantNumber AdvancedColors2Types = "Number" - AdvancedColors2TypeVariantNumberArray AdvancedColors2Types = "NumberArray" + AdvancedColors2TypeVariantString AdvancedColors2Types = "string" + AdvancedColors2TypeVariantNumber AdvancedColors2Types = "number" + AdvancedColors2TypeVariantNumberArray AdvancedColors2Types = "number-array" // Comment on the last element - AdvancedColors2TypeVariantReallyCoolType AdvancedColors2Types = "ReallyCoolType" + AdvancedColors2TypeVariantReallyCoolType AdvancedColors2Types = "really-cool-type" ) type AdvancedColors2 struct{ Type AdvancedColors2Types `json:"type"` diff --git a/core/data/tests/can_handle_unit_type/output.go b/core/data/tests/can_handle_unit_type/output.go index b2c7faf2..6c8bb5bb 100644 --- a/core/data/tests/can_handle_unit_type/output.go +++ b/core/data/tests/can_handle_unit_type/output.go @@ -9,7 +9,7 @@ type StructHasVoidType struct { // This enum has a variant associated with unit data type EnumHasVoidTypeTypes string const ( - EnumHasVoidTypeTypeVariantHasAUnit EnumHasVoidTypeTypes = "HasAUnit" + EnumHasVoidTypeTypeVariantHasAUnit EnumHasVoidTypeTypes = "hasAUnit" ) type EnumHasVoidType struct{ Type EnumHasVoidTypeTypes `json:"type"` diff --git a/core/data/tests/recursive_enum_decorator/output.go b/core/data/tests/recursive_enum_decorator/output.go index fde053a9..ce31fdf4 100644 --- a/core/data/tests/recursive_enum_decorator/output.go +++ b/core/data/tests/recursive_enum_decorator/output.go @@ -12,9 +12,9 @@ type MoreOptionsBuiltInner struct { } type MoreOptionsTypes string const ( - MoreOptionsTypeVariantNews MoreOptionsTypes = "News" - MoreOptionsTypeVariantExactly MoreOptionsTypes = "Exactly" - MoreOptionsTypeVariantBuilt MoreOptionsTypes = "Built" + MoreOptionsTypeVariantNews MoreOptionsTypes = "news" + MoreOptionsTypeVariantExactly MoreOptionsTypes = "exactly" + MoreOptionsTypeVariantBuilt MoreOptionsTypes = "built" ) type MoreOptions struct{ Type MoreOptionsTypes `json:"type"` @@ -94,9 +94,9 @@ func NewMoreOptionsTypeVariantBuilt(content *MoreOptionsBuiltInner) MoreOptions type OptionsTypes string const ( - OptionsTypeVariantRed OptionsTypes = "Red" - OptionsTypeVariantBanana OptionsTypes = "Banana" - OptionsTypeVariantVermont OptionsTypes = "Vermont" + OptionsTypeVariantRed OptionsTypes = "red" + OptionsTypeVariantBanana OptionsTypes = "banana" + OptionsTypeVariantVermont OptionsTypes = "vermont" ) type Options struct{ Type OptionsTypes `json:"type"` diff --git a/core/data/tests/test_algebraic_enum_case_name_support/output.go b/core/data/tests/test_algebraic_enum_case_name_support/output.go index 9e734693..b2587623 100644 --- a/core/data/tests/test_algebraic_enum_case_name_support/output.go +++ b/core/data/tests/test_algebraic_enum_case_name_support/output.go @@ -6,10 +6,10 @@ type ItemDetailsFieldValue struct { } type AdvancedColorsTypes string const ( - AdvancedColorsTypeVariantString AdvancedColorsTypes = "String" - AdvancedColorsTypeVariantNumber AdvancedColorsTypes = "Number" - AdvancedColorsTypeVariantNumberArray AdvancedColorsTypes = "NumberArray" - AdvancedColorsTypeVariantReallyCoolType AdvancedColorsTypes = "ReallyCoolType" + AdvancedColorsTypeVariantString AdvancedColorsTypes = "string" + AdvancedColorsTypeVariantNumber AdvancedColorsTypes = "number" + AdvancedColorsTypeVariantNumberArray AdvancedColorsTypes = "number-array" + AdvancedColorsTypeVariantReallyCoolType AdvancedColorsTypes = "reallyCoolType" ) type AdvancedColors struct{ Type AdvancedColorsTypes `json:"type"`