diff --git a/config/config.go b/config/config.go index e693fd0..d1f2a8b 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..5decc94 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -272,6 +272,11 @@ 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 the field list is non-empty, this is a struct if len(info.Fields) > 0 { typeDef.Kind = types.StructKind