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

Fix sidebar placement of resources generated by tpgtools #5890

Merged
merged 1 commit into from
Apr 4, 2022
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
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