utils

package
v0.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package utils provides utility functions for the gcloud generator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractPathFromSegments added in v0.8.2

func ExtractPathFromSegments(segments []api.PathSegment) string

ExtractPathFromSegments extracts the dot-separated collection path from path segments. It handles: 1. Skipping API version prefixes (e.g., v1). 2. Extracting internal structure from complex variables (e.g., {name=projects/*/locations/*}). 3. Including all literal segments (e.g., instances in .../instances).

func FindResourceMessage added in v0.8.2

func FindResourceMessage(outputType *api.Message) *api.Message

FindResourceMessage identifies the primary resource message within a List response. Per AIP-132, this is usually the repeated field in the response message.

func GetCollectionPathFromSegments

func GetCollectionPathFromSegments(segments []api.PathSegment) string

GetCollectionPathFromSegments constructs the base gcloud collection path from a structured resource pattern, according to AIP-122 conventions. It joins the literal collection identifiers with dots. Example: `projects/{project}/locations/{location}/instances/{instance}` -> `projects.locations.instances`.

func GetCommandName

func GetCommandName(method *api.Method) (string, error)

GetCommandName maps an API method to a standard gcloud command name (in snake_case). This name is typically used for the command's file name.

func GetGcloudType

func GetGcloudType(t api.Typez) string

GetGcloudType maps an API field type to the corresponding gcloud argparse type.

func GetParentFromSegments added in v0.8.1

func GetParentFromSegments(segments []api.PathSegment) []api.PathSegment

GetParentFromSegments extracts the pattern segments for the parent resource. It assumes the standard resource pattern structure where the last two segments are the literal plural noun and the variable singular noun of the child resource. Example: `projects/.../locations/{location}/instances/{instance}` -> `projects/.../locations/{location}`.

func GetPluralFromSegments

func GetPluralFromSegments(segments []api.PathSegment) string

GetPluralFromSegments infers the plural name of a resource from its structured path segments. Per AIP-122, the plural is the literal segment before the final variable segment. Example: `.../instances/{instance}` -> "instances".

func GetPluralResourceNameForMethod

func GetPluralResourceNameForMethod(method *api.Method, model *api.API) string

GetPluralResourceNameForMethod determines the plural name of a resource. It follows a clear hierarchy of truth: first, the explicit `plural` field in the resource definition, and second, inference from the resource pattern.

func GetResourceForMethod

func GetResourceForMethod(method *api.Method, model *api.API) *api.Resource

GetResourceForMethod finds the `api.Resource` definition associated with a method. This is a crucial function for linking a method to the resource it operates on.

func GetServiceTitle

func GetServiceTitle(model *api.API, shortServiceName string) string

GetServiceTitle returns the service title for documentation. It tries to use the API title, falling back to a CamelCase version of the short service name.

func GetSingularFromSegments

func GetSingularFromSegments(segments []api.PathSegment) string

GetSingularFromSegments infers the singular name of a resource from its structured path segments. According to AIP-123, the last segment of a resource pattern MUST be a variable representing the resource ID, and its name MUST be the singular form of the resource noun. Example: `.../instances/{instance}` -> "instance".

func GetSingularResourceNameForMethod

func GetSingularResourceNameForMethod(method *api.Method, model *api.API) string

GetSingularResourceNameForMethod determines the singular name of a resource. It follows a clear hierarchy of truth: first, the explicit `singular` field in the resource definition, and second, inference from the resource pattern.

func InferTrackFromPackage

func InferTrackFromPackage(pkg string) string

InferTrackFromPackage infers the release track from the proto package name. as mandated per AIP-185 e.g. "google.cloud.parallelstore.v1beta" -> "beta".

func IsCollectionMethod added in v0.8.1

func IsCollectionMethod(m *api.Method) bool

IsCollectionMethod determines if the method operates on a collection of resources. This includes standard List and Create methods, and custom methods where the HTTP path ends with a literal segment (e.g. `.../instances`).

func IsCreate

func IsCreate(m *api.Method) bool

IsCreate determines if the method is a standard Create method (AIP-133).

func IsDelete

func IsDelete(m *api.Method) bool

IsDelete determines if the method is a standard Delete method (AIP-135).

func IsGet

func IsGet(m *api.Method) bool

IsGet determines if the method is a standard Get method (AIP-131).

func IsList

func IsList(m *api.Method) bool

IsList determines if the method is a standard List method (AIP-132).

func IsPrimaryResource

func IsPrimaryResource(field *api.Field, method *api.Method) bool

IsPrimaryResource determines if a field represents the primary resource of a method.

func IsResourceMethod added in v0.8.1

func IsResourceMethod(m *api.Method) bool

IsResourceMethod determines if the method operates on a specific resource instance. This includes standard Get, Update, Delete methods, and custom methods where the HTTP path ends with a variable segment (e.g. `.../instances/{instance}`).

func IsSafeName added in v0.8.2

func IsSafeName(name string) bool

IsSafeName checks if a name contains only safe characters (alphanumeric, underscores, dots). This prevents injection vulnerabilities when generating code or templates.

func IsStandardMethod added in v0.8.2

func IsStandardMethod(m *api.Method) bool

IsStandardMethod determines if the method is one of the standard AIP methods (Get, List, Create, Update, Delete).

func IsUpdate

func IsUpdate(m *api.Method) bool

IsUpdate determines if the method is a standard Update method (AIP-134).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL