Documentation
¶
Overview ¶
Package utils provides utility functions for the gcloud generator.
Index ¶
- func GetCollectionPathFromSegments(segments []api.PathSegment) string
- func GetCommandName(method *api.Method) (string, error)
- func GetGcloudType(t api.Typez) string
- func GetParentFromSegments(segments []api.PathSegment) []api.PathSegment
- func GetPluralFromSegments(segments []api.PathSegment) string
- func GetPluralResourceNameForMethod(method *api.Method, model *api.API) string
- func GetResourceForMethod(method *api.Method, model *api.API) *api.Resource
- func GetServiceTitle(model *api.API, shortServiceName string) string
- func GetSingularFromSegments(segments []api.PathSegment) string
- func GetSingularResourceNameForMethod(method *api.Method, model *api.API) string
- func InferTrackFromPackage(pkg string) string
- func IsCollectionMethod(m *api.Method) bool
- func IsCreate(m *api.Method) bool
- func IsDelete(m *api.Method) bool
- func IsGet(m *api.Method) bool
- func IsList(m *api.Method) bool
- func IsPrimaryResource(field *api.Field, method *api.Method) bool
- func IsResourceMethod(m *api.Method) bool
- func IsUpdate(m *api.Method) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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
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 IsPrimaryResource ¶
IsPrimaryResource determines if a field represents the primary resource of a method.
func IsResourceMethod ¶ added in v0.8.1
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}`).
Types ¶
This section is empty.