From ea281f581d2bb1e15b66f4f3a7663e6490f6514a Mon Sep 17 00:00:00 2001 From: Lukas Jenicek Date: Fri, 16 Feb 2024 11:54:31 +0100 Subject: [PATCH] support string enums as string union type --- _examples/node-ts/service.ridl | 4 ++++ types.go.tmpl | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/_examples/node-ts/service.ridl b/_examples/node-ts/service.ridl index a121481..a2f4465 100644 --- a/_examples/node-ts/service.ridl +++ b/_examples/node-ts/service.ridl @@ -8,6 +8,10 @@ enum Kind: uint32 - USER - ADMIN +enum Intent: string + - openSession + - closeSession + - validateSession struct User - ID: uint64 diff --git a/types.go.tmpl b/types.go.tmpl index 1493a87..898089e 100644 --- a/types.go.tmpl +++ b/types.go.tmpl @@ -12,11 +12,19 @@ {{range $_i, $type := $types -}} {{if isEnumType $type }} -export enum {{$type.Name}} { -{{- range $i, $field := $type.Fields}} - {{- if $i}},{{end}} - {{$field.Name}} = '{{$field.Name}}' -{{- end}} + {{- if eq $type.Type.Expr "string" }} + export {{$type.Name}} = + {{- range $i, $field := $type.Fields}} + {{- if $i}}|{{end}} '{{$field.Name}}' + {{- end}} + {{ else }} + export enum {{$type.Name}} { + {{- range $i, $field := $type.Fields}} + {{- if $i}},{{end}} + {{$field.Name}} = '{{$field.Name}}' + {{- end}} + {{ end -}} +{{- if $type.}} } {{end -}}