Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.
Open
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
33 changes: 20 additions & 13 deletions generator/minimal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ func (g *Generator) Generate(d *descriptor.FileDescriptorProto) ([]*plugin.CodeG
model.Fields = append(model.Fields, newField(f))
}

ctx.Enums = append(ctx.Enums, extractEnums(m.GetEnumType())...)
ctx.AddModel(model)
}

Expand Down Expand Up @@ -326,19 +327,7 @@ func (g *Generator) Generate(d *descriptor.FileDescriptorProto) ([]*plugin.CodeG
ctx.Services = append(ctx.Services, service)
}

for _, e := range d.GetEnumType() {
options := make([]EnumOption, 0)
for _, x := range e.GetValue() {
options = append(options, EnumOption{
Key: x.GetName(),
Value: x.GetNumber(),
})
}
ctx.Enums = append(ctx.Enums, &Enum{
Name: e.GetName(),
Options: options,
})
}
ctx.Enums = append(ctx.Enums, extractEnums(d.GetEnumType())...)

// Only include the custom 'ToJSON' and 'JSONTo' methods in generated code
// if the Model is part of an rpc method input arg or return type.
Expand Down Expand Up @@ -558,3 +547,21 @@ func parse(f ModelField, modelName string) string {

return field
}

func extractEnums(d []*descriptor.EnumDescriptorProto) []*Enum {
enums := make([]*Enum, 0)
for _, e := range d {
options := make([]EnumOption, 0)
for _, x := range e.GetValue() {
options = append(options, EnumOption{
Key: x.GetName(),
Value: x.GetNumber(),
})
}
enums = append(enums, &Enum{
Name: e.GetName(),
Options: options,
})
}
return enums
}