Skip to content

Commit

Permalink
Fix sidebar placement of resources generated by tpgtools (#5890)
Browse files Browse the repository at this point in the history
  • Loading branch information
c2thorn authored Apr 4, 2022
1 parent c776122 commit 6fb57b6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
22 changes: 22 additions & 0 deletions tpgtools/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type lowercaseName interface {
lowercase() string
}

type kebabCaseName interface {
kebabcase() string
}

// e.g. `google_compute_instance` or `google_orgpolicy_policy`.
type SnakeCaseTerraformResourceName string

Expand Down Expand Up @@ -74,6 +78,18 @@ func snakeToTitleCase(s snakeCaseName) miscellaneousNameTitleCase {
return miscellaneousNameTitleCase(strings.Join(snakeToParts(s, true), ""))
}

// e.g. `google-compute-instance` or `google-orgpolicy-policy`.
type KebabCaseTerraformResourceName string

// snakeToKebabCase converts a snake_case string to kebab case.
func snakeToKebabCase(s snakeCaseName) miscellaneousNameKebabCase {
return miscellaneousNameKebabCase(strings.Join(snakeToParts(s, false), "-"))
}

func (s SnakeCaseFullName) ToKebab() RenderedString {
return RenderedString(snakeToKebabCase(s).kebabcase())
}

// A type for a string that is not meant for further conversion. Some functions return a
// RenderedString to indicate that they have been lossily converted to another format.
type RenderedString string
Expand Down Expand Up @@ -143,3 +159,9 @@ type miscellaneousNameLowercase string
func (m miscellaneousNameLowercase) lowercase() string {
return string(m)
}

type miscellaneousNameKebabCase string

func (m miscellaneousNameKebabCase) kebabcase() string {
return string(m)
}
28 changes: 17 additions & 11 deletions tpgtools/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ func (r Resource) TerraformName() SnakeCaseFullName {
return SnakeCaseFullName(concatenateSnakeCase(googlePrefix, r.ProductName(), r.Name()))
}

// TerraformName is the Terraform resource type used for the sidebar_current field in documentation.
// For example, "google-compute-instance"
func (r Resource) SidebarCurrentName() KebabCaseTerraformResourceName {
return KebabCaseTerraformResourceName(r.TerraformName().ToKebab())
}

// PathType is the title-cased name of a resource preceded by its package,
// often used to namespace functions. For example, "RedisInstance".
func (r Resource) PathType() TitleCaseFullName {
Expand Down Expand Up @@ -492,17 +498,17 @@ func createResource(schema *openapi.Schema, info *openapi.Info, typeFetcher *Typ
res.Properties = props

onlyLongFormFormat := shouldAllowForwardSlashInFormat(res.ID, res.Properties)
// Resource Override: Import formats
ifd := ImportFormatDetails{}
ifdOk, err := overrides.ResourceOverrideWithDetails(ImportFormat, &ifd, location)
if err != nil {
return nil, fmt.Errorf("failed to decode import format details: %v", err)
}
if ifdOk {
res.ImportFormats = ifd.Formats
} else {
res.ImportFormats = defaultImportFormats(res.ID, onlyLongFormFormat)
}
// Resource Override: Import formats
ifd := ImportFormatDetails{}
ifdOk, err := overrides.ResourceOverrideWithDetails(ImportFormat, &ifd, location)
if err != nil {
return nil, fmt.Errorf("failed to decode import format details: %v", err)
}
if ifdOk {
res.ImportFormats = ifd.Formats
} else {
res.ImportFormats = defaultImportFormats(res.ID, onlyLongFormFormat)
}

_, res.HasProject = schema.Properties["project"]

Expand Down
1 change: 1 addition & 0 deletions tpgtools/templates/resource.html.markdown.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
subcategory: "{{$.DocsSection}}"
layout: "google"
page_title: "Google: {{$.TerraformName}}"
sidebar_current: "docs-{{$.SidebarCurrentName}}"
description: |-
{{$.Description}}
---
Expand Down

0 comments on commit 6fb57b6

Please sign in to comment.