Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tpgtools spit out working documentation. #5165

Merged
merged 2 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tpgtools/api/gkehub/beta/feature_membership.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ components:
type: object
x-dcl-go-name: Binauthz
x-dcl-go-type: FeatureMembershipConfigmanagementBinauthz
description: Binauthz conifguration for the cluster.
description: Binauthz configuration for the cluster.
properties:
enabled:
type: boolean
Expand Down Expand Up @@ -236,4 +236,4 @@ components:
x-dcl-references:
- resource: Cloudresourcemanager/Project
field: name
parent: true
parent: true
9 changes: 5 additions & 4 deletions tpgtools/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,11 @@ func generateProductsFile(fileName string, products []*ProductMetadata) {
}

var TemplateFunctions = template.FuncMap{
"title": strings.Title,
"patternToRegex": PatternToRegex,
"replace": strings.Replace,
"isLastIndex": isLastIndex,
"title": strings.Title,
"patternToRegex": PatternToRegex,
"replace": strings.Replace,
"isLastIndex": isLastIndex,
"escapeDescription": escapeDescription,
}

// TypeFetcher fetches reused types, as marked by the $ref field being marked on an OpenAPI schema.
Expand Down
4 changes: 4 additions & 0 deletions tpgtools/main_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func formatComparator(formats []string) func(i, j int) bool {
}
}

func escapeDescription(in string) string {
return strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(in, `\`, `\\`), `"`, `\"`), "\n", `\n`)
}

func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
Expand Down
4 changes: 2 additions & 2 deletions tpgtools/templates/resource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func resource{{$.PathType}}() *schema.Resource {
{{- if $p.DiffSuppressFunc }}
DiffSuppressFunc: {{$p.DiffSuppressFunc}},
{{- end }}
Description: `{{/* TODO fix formatting for $p.Description - see https://github.com/hashicorp/terraform-provider-google/issues/9197 */}}`,
Description: "{{escapeDescription $p.Description}}",
{{- if $p.MaxItems }}
MaxItems: {{$p.MaxItems}},
{{- end }}
Expand Down Expand Up @@ -158,7 +158,7 @@ func {{$.PathType}}{{$v.PackagePath}}Schema() *schema.Resource {
{{- if $p.DiffSuppressFunc }}
DiffSuppressFunc: {{$p.DiffSuppressFunc}},
{{- end }}
Description: `{{/* TODO fix formatting for $p.Description */}}`,
Description: "{{escapeDescription $p.Description}}",
{{- if $p.MaxItems }}
MaxItems: {{$p.MaxItems}},
{{- end }}
Expand Down