diff --git a/inspector.go b/inspector.go index 394c458..d60631e 100644 --- a/inspector.go +++ b/inspector.go @@ -235,11 +235,12 @@ func (i *inspector) parseField(f *ast.Field) (out []envField) { item.typeRef = fieldType.Name case *ast.StructType: nameGen := fastRandString(16) - i.getStruct(&ast.TypeSpec{ + typeSpec := &ast.TypeSpec{ Name: &ast.Ident{Name: nameGen}, Type: fieldType, - Doc: &ast.CommentGroup{List: f.Doc.List}, - }) + Doc: f.Doc, + } + i.getStruct(typeSpec) item.typeRef = nameGen posRange := [2]token.Pos{fieldType.Pos(), fieldType.End()} i.anonymousStructs[posRange] = anonymousStruct{ diff --git a/inspector_test.go b/inspector_test.go index 157bfbf..38c936a 100644 --- a/inspector_test.go +++ b/inspector_test.go @@ -362,6 +362,20 @@ func TestInspector(t *testing.T) { }, }, }, + { + name: "nodocs.go", + typeName: "Config", + expect: []EnvDocItem{ + { + Children: []EnvDocItem{ + { + Name: "REPO_CONN", + Opts: EnvVarOptions{Required: true, NonEmpty: true}, + }, + }, + }, + }, + }, } { scopes := c.expectScopes if scopes == nil { diff --git a/testdata/nodocs.go b/testdata/nodocs.go new file mode 100644 index 0000000..0694d4e --- /dev/null +++ b/testdata/nodocs.go @@ -0,0 +1,7 @@ +package main + +type Config struct { + Repo struct { + Conn string `env:"CONN,notEmpty"` + } `envPrefix:"REPO_"` +}