diff --git a/pkg/docgen/docgen.go b/pkg/docgen/docgen.go index be82bab..b618b8a 100644 --- a/pkg/docgen/docgen.go +++ b/pkg/docgen/docgen.go @@ -304,6 +304,7 @@ func (d *Doc) getValuesFromItem(item *ast.Field) (name, comment, def, required s } } } + commentWithDefault = strings.TrimSuffix(commentWithDefault, " ") if item.Tag == nil { return "", "", "", "", errors.Errorf("field has no tag defined: %+v", item) } diff --git a/pkg/docgen/docgen_test.go b/pkg/docgen/docgen_test.go index b2bb01a..1ffcace 100644 --- a/pkg/docgen/docgen_test.go +++ b/pkg/docgen/docgen_test.go @@ -74,6 +74,23 @@ func TestGenParse(t *testing.T) { Default: testval + `), + }, + { + docItem: docgen.DocItem{ + Name: "sample-comment", + SourcePath: filepath.Join(currentDir, "testdata", "sample_comment.go"), + DestPath: filepath.Join(currentDir, "../../build/_test/docgen"), + }, + expected: heredoc.Doc(` + ## SampleComment + + ### field1 (string, optional) {#samplecomment-field1} + + Field1 is a good field. + + + `), }, { diff --git a/pkg/docgen/testdata/sample_comment.go b/pkg/docgen/testdata/sample_comment.go new file mode 100644 index 0000000..ae49a18 --- /dev/null +++ b/pkg/docgen/testdata/sample_comment.go @@ -0,0 +1,20 @@ +// Copyright © 2020 Banzai Cloud +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package testdata + +type SampleComment struct { + // Field1 is a good field. + Field1 string `json:"field1,omitempty"` +}