Skip to content

Commit

Permalink
support string enums as string union type
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJenicek committed Feb 16, 2024
1 parent 0d4f888 commit ea281f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions _examples/node-ts/service.ridl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ enum Kind: uint32
- USER
- ADMIN

enum Intent: string
- openSession
- closeSession
- validateSession

struct User
- ID: uint64
Expand Down
18 changes: 13 additions & 5 deletions types.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

Expand Down

0 comments on commit ea281f5

Please sign in to comment.