Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add list of enums #486

Merged
merged 2 commits into from
Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions codegen/codegen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func TestGenerateServer(t *testing.T) {
id: Int
fist_name: String
}
enum Status {
OK
ERROR
}
`
serverFilename := "gen/" + name + "/server/server.go"
cfg := Config{
Expand All @@ -42,4 +46,30 @@ func TestGenerateServer(t *testing.T) {

_, err = conf.Load()
require.NoError(t, err)

t.Run("list of enums", func(t *testing.T) {
conf = loader.Config{}
conf.CreateFromFilenames("gen/"+name, "gen/"+name+"/model.go")

program, err := conf.Load()
require.NoError(t, err)

found := false

for _, c := range program.Created {
for ident := range c.Defs {
if ident.Name == "AllStatus" {
found = true
break
}
}
if found {
break
}
}

if !found {
t.Fail()
}
})
}
2 changes: 1 addition & 1 deletion codegen/templates/data.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions codegen/templates/models.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ import (
{{- end }}
)

var All{{.GoType}} = []{{.GoType}}{
{{- range $value := .Values}}
{{$enum.GoType}}{{ .Name|toCamel }},
{{- end }}
}

func (e {{.GoType}}) IsValid() bool {
switch e {
case {{ range $index, $element := .Values}}{{if $index}},{{end}}{{ $enum.GoType }}{{ $element.Name|toCamel }}{{end}}:
Expand Down
11 changes: 11 additions & 0 deletions example/starwars/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions example/todo/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions example/type-system-extension/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions integration/models-go/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.