From 3e803579453a5842698ea7f8651d08888c98daec Mon Sep 17 00:00:00 2001 From: Nathan Mckinley Date: Wed, 1 Sep 2021 17:21:40 -0700 Subject: [PATCH 1/2] Make tpgtools spit out working documentation. --- tpgtools/main.go | 9 +++++---- tpgtools/main_helpers.go | 4 ++++ tpgtools/templates/resource.go.tmpl | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tpgtools/main.go b/tpgtools/main.go index 4ef2796399f2..9a5527c7dd1e 100644 --- a/tpgtools/main.go +++ b/tpgtools/main.go @@ -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. diff --git a/tpgtools/main_helpers.go b/tpgtools/main_helpers.go index 05817d8f42a9..0058cad71649 100644 --- a/tpgtools/main_helpers.go +++ b/tpgtools/main_helpers.go @@ -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 { diff --git a/tpgtools/templates/resource.go.tmpl b/tpgtools/templates/resource.go.tmpl index 3464fb271055..aaf06abceb1f 100644 --- a/tpgtools/templates/resource.go.tmpl +++ b/tpgtools/templates/resource.go.tmpl @@ -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 }} @@ -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 }} From def144ed78eeabec36d7c90bbca2f8d8455027c5 Mon Sep 17 00:00:00 2001 From: Nathan Mckinley Date: Wed, 1 Sep 2021 17:41:25 -0700 Subject: [PATCH 2/2] Fix typo. typo is also present in dcl config, will fix that separately. --- tpgtools/api/gkehub/beta/feature_membership.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tpgtools/api/gkehub/beta/feature_membership.yaml b/tpgtools/api/gkehub/beta/feature_membership.yaml index c14ee786b35d..7711259689d4 100644 --- a/tpgtools/api/gkehub/beta/feature_membership.yaml +++ b/tpgtools/api/gkehub/beta/feature_membership.yaml @@ -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 @@ -236,4 +236,4 @@ components: x-dcl-references: - resource: Cloudresourcemanager/Project field: name - parent: true \ No newline at end of file + parent: true