Skip to content

Commit 14f4431

Browse files
authored
fix: allow field hooks to omit a field from code generation (#3814)
A field hook may return nil which results in a nil-pointer deref later on. This checks for nil and returns immediately to avoid this and effectively allow field hooks to omit a field entirely.
1 parent d5384a2 commit 14f4431

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

plugin/modelgen/models.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,12 @@ func (m *Plugin) generateField(
441441
if err != nil {
442442
return nil, fmt.Errorf("generror: field %v.%v: %w", schemaType.Name, field.Name, err)
443443
}
444+
445+
if mf == nil {
446+
// the field hook wants to omit the field
447+
return nil, nil
448+
}
449+
444450
f = mf
445451
}
446452

0 commit comments

Comments
 (0)