Skip to content

Commit

Permalink
added support for optional enums for gorm protoc generator. (#281)
Browse files Browse the repository at this point in the history
* added support for optional enums for gorm protoc generator.

based on the issue I opened here:

#280

* return missing line from code that handles b.stringEnums
  • Loading branch information
RomanSter authored Dec 9, 2024
1 parent c61100d commit 7402b54
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -1459,12 +1459,16 @@ func (b *ORMBuilder) generateFieldConversion(message *protogen.Message, field *p
if toORM {
if b.stringEnums {
g.P(`to.`, fieldName, ` = `, fieldType, `_name[int32(m.`, fieldName, `)]`)
} else if field.Desc.HasOptionalKeyword() {
g.P(`to.`, fieldName, ` = (*int32)(m.`, fieldName, `)`)
} else {
g.P(`to.`, fieldName, ` = int32(m.`, fieldName, `)`)
}
} else {
if b.stringEnums {
g.P(`to.`, fieldName, ` = `, fieldType, `(`, fieldType, `_value[m.`, fieldName, `])`)
} else if field.Desc.HasOptionalKeyword() {
g.P(`to.`, fieldName, ` = (*`, fieldType, `)(m.`, fieldName, `)`)
} else {
g.P(`to.`, fieldName, ` = `, fieldType, `(m.`, fieldName, `)`)
}
Expand Down

0 comments on commit 7402b54

Please sign in to comment.