Skip to content

Commit 8502711

Browse files
Fix docs panic with scaleway bucket (#2455)
The scaleway bucket docs have extra newlines so our nested argument parsing fails but our code does not handle that and panics. This fixes the panic, ~the parsing is left as a follow-up.~ The docs are already fine: https://www.pulumi.com/registry/packages/scaleway/api-docs/objectbucket/#objectbucketversioning fixes #2453
1 parent 65dd45d commit 8502711

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

pkg/tfgen/docs.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,10 @@ func parseArgReferenceSection(subsection []string, ret *entityDocs) {
10751075
return
10761076
}
10771077
line = "\n" + strings.TrimSpace(line)
1078-
ret.Arguments[docsPath(lastMatch)].description += line
1078+
arg := ret.Arguments[docsPath(lastMatch)]
1079+
if arg != nil {
1080+
arg.description += line
1081+
}
10791082
}
10801083
}
10811084

pkg/tfgen/docs_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,41 @@ func TestArgumentRegex(t *testing.T) {
624624
}
625625
}
626626

627+
func TestArgumentRegexAuto(t *testing.T) {
628+
tests := []struct {
629+
name string
630+
input []string
631+
expected autogold.Value
632+
}{
633+
{
634+
name: "newline after bullet",
635+
input: []string{
636+
"",
637+
"The following arguments are supported:",
638+
"",
639+
"* `versioning` - (Optional) A state of [versioning](https://www.scaleway.com/en/docs/storage/object/how-to/use-bucket-versioning/). The `versioning` object supports the following:",
640+
"",
641+
" * `enabled` - (Optional) Enable versioning. Once you version-enable a bucket, it can never return to an unversioned state. You can, however, suspend versioning on that bucket.",
642+
"",
643+
},
644+
expected: autogold.Expect(map[docsPath]*argumentDocs{docsPath("versioning.enabled"): {
645+
description: "Enable versioning. Once you version-enable a bucket, it can never return to an unversioned state. You can, however, suspend versioning on that bucket.",
646+
}}),
647+
},
648+
}
649+
650+
for _, tt := range tests {
651+
tt := tt
652+
t.Run(tt.name, func(t *testing.T) {
653+
ret := entityDocs{
654+
Arguments: make(map[docsPath]*argumentDocs),
655+
}
656+
parseArgReferenceSection(tt.input, &ret)
657+
tt.expected.Equal(t, ret.Arguments)
658+
})
659+
}
660+
}
661+
627662
func TestGetFooterLinks(t *testing.T) {
628663
input := `## Attributes Reference
629664

0 commit comments

Comments
 (0)