From 35825ff08c79d29103af01c68ae2141223b2a6f4 Mon Sep 17 00:00:00 2001 From: Zadkiel AHARONIAN Date: Fri, 11 Apr 2025 17:43:18 +0200 Subject: [PATCH 1/5] fix: remove trailing spaces in descriptions --- pkg/docgen/docgen.go | 1 + 1 file changed, 1 insertion(+) 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) } From f4628198675a8c58e555c558b109f9a904e0adbf Mon Sep 17 00:00:00 2001 From: Zadkiel AHARONIAN Date: Fri, 11 Apr 2025 17:47:30 +0200 Subject: [PATCH 2/5] Add sample_comment test data and test case --- pkg/docgen/docgen_test.go | 16 ++++++++++++++++ pkg/docgen/testdata/sample_comment.go | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 pkg/docgen/testdata/sample_comment.go diff --git a/pkg/docgen/docgen_test.go b/pkg/docgen/docgen_test.go index b2bb01a..06f29f7 100644 --- a/pkg/docgen/docgen_test.go +++ b/pkg/docgen/docgen_test.go @@ -74,6 +74,22 @@ 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..c4e9ee1 --- /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"` +} \ No newline at end of file From a02d082ccd9906eca62f34d7f45b0ed47a77c755 Mon Sep 17 00:00:00 2001 From: Zadkiel AHARONIAN Date: Fri, 11 Apr 2025 17:47:56 +0200 Subject: [PATCH 3/5] Add newline at end of sample_comment.go file From e8bea897ec4ea29af254997cec10f490e2ec0e37 Mon Sep 17 00:00:00 2001 From: Zadkiel AHARONIAN Date: Fri, 11 Apr 2025 17:48:43 +0200 Subject: [PATCH 4/5] Update sample_comment.go --- pkg/docgen/testdata/sample_comment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/docgen/testdata/sample_comment.go b/pkg/docgen/testdata/sample_comment.go index c4e9ee1..ae49a18 100644 --- a/pkg/docgen/testdata/sample_comment.go +++ b/pkg/docgen/testdata/sample_comment.go @@ -17,4 +17,4 @@ package testdata type SampleComment struct { // Field1 is a good field. Field1 string `json:"field1,omitempty"` -} \ No newline at end of file +} From e3904883f18163a14892e7b0c8e24637fda5cb70 Mon Sep 17 00:00:00 2001 From: Zadkiel AHARONIAN Date: Fri, 11 Apr 2025 17:52:24 +0200 Subject: [PATCH 5/5] Add newline in docgen_test.go --- pkg/docgen/docgen_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/docgen/docgen_test.go b/pkg/docgen/docgen_test.go index 06f29f7..1ffcace 100644 --- a/pkg/docgen/docgen_test.go +++ b/pkg/docgen/docgen_test.go @@ -90,6 +90,7 @@ func TestGenParse(t *testing.T) { Field1 is a good field. + `), }, {