diff --git a/config/config.go b/config/config.go index e693fd0..447490a 100644 --- a/config/config.go +++ b/config/config.go @@ -33,6 +33,7 @@ type ProcessorConfig struct { IgnoreTypes []string `json:"ignoreTypes"` IgnoreFields []string `json:"ignoreFields"` IgnoreGroupVersions []string `json:"ignoreGroupVersions"` + UseRawDocstring bool `json:"UseRawDocstring"` } type RenderConfig struct { diff --git a/processor/config.go b/processor/config.go index 5fa03a5..ec479be 100644 --- a/processor/config.go +++ b/processor/config.go @@ -32,6 +32,7 @@ func compileConfig(conf *config.Config) (cc *compiledConfig, err error) { ignoreTypes: make([]*regexp.Regexp, len(conf.Processor.IgnoreTypes)), ignoreFields: make([]*regexp.Regexp, len(conf.Processor.IgnoreFields)), ignoreGroupVersions: make([]*regexp.Regexp, len(conf.Processor.IgnoreGroupVersions)), + useRawDocstring: conf.Processor.UseRawDocstring, } for i, t := range conf.Processor.IgnoreTypes { @@ -59,6 +60,7 @@ type compiledConfig struct { ignoreTypes []*regexp.Regexp ignoreFields []*regexp.Regexp ignoreGroupVersions []*regexp.Regexp + useRawDocstring bool } func (cc *compiledConfig) shouldIgnoreGroupVersion(gv string) bool { diff --git a/processor/processor.go b/processor/processor.go index 17792b4..e5c5a39 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -272,6 +272,16 @@ func (p *processor) processType(pkg *loader.Package, info *markers.TypeInfo, dep Doc: info.Doc, } + if p.useRawDocstring && info.RawDecl != nil { + // use raw docstring to support multi-line and indent preservation + typeDef.Doc = strings.TrimSuffix(info.RawDecl.Doc.Text(), "\n") + } + + if p.shouldIgnoreType(types.Key(typeDef)) { + zap.S().Debugw("Skipping excluded type", "type", typeDef.String()) + return nil + } + // if the field list is non-empty, this is a struct if len(info.Fields) > 0 { typeDef.Kind = types.StructKind