utils

package
v1.29.6 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeclarativeFriendlyResource

func DeclarativeFriendlyResource(d desc.Descriptor) *desc.MessageDescriptor

DeclarativeFriendlyResource returns the declarative-friendly resource associated with this descriptor.

For messages: If the message is annotated with google.api.resource and style: DECLARATIVE_FRIENDLY is set, that message is returned. If the message is a standard method request message for a resource with google.api.resource and style:DECLARATIVE_FRIENDLY set, then the resource is returned.

For methods: If the output message is a declarative-friendly resource, it is returned. If the method begins with "List" and the first repeated field is a declarative-friendly resource, the resource is returned. If the method begins with "Delete", the return type is Empty, and an appropriate resource message is found and is declarative-friendly, that resource is returned. If the method is a custom method where a matching resource is found (by subset checks on the name) and is declarative-friendly, the resource is returned.

If there is no declarative-friendly resource, it returns nil.

func FindMessage

func FindMessage(f *desc.FileDescriptor, name string) *desc.MessageDescriptor

FindMessage looks for a message in a file and all imports within the same package.

func FindMethod

func FindMethod(f *desc.FileDescriptor, name string) *desc.MethodDescriptor

FindMethod searches a file and all imports within the same package, and returns the method with a given name, or nil if none is found.

func GetAllDependencies

func GetAllDependencies(file *desc.FileDescriptor) map[string]*desc.FileDescriptor

GetAllDependencies returns all dependencies.

func GetFieldBehavior

func GetFieldBehavior(f *desc.FieldDescriptor) stringset.Set

GetFieldBehavior returns a stringset.Set of FieldBehavior annotations for the given field.

func GetMethodSignatures

func GetMethodSignatures(m *desc.MethodDescriptor) [][]string

GetMethodSignatures returns the `google.api.method_signature` annotations.

func GetOperationInfo

func GetOperationInfo(m *desc.MethodDescriptor) *lrpb.OperationInfo

GetOperationInfo returns the google.longrunning.operation_info annotation.

func GetResource

GetResource returns the google.api.resource annotation.

func GetResourceDefinitions

func GetResourceDefinitions(f *desc.FileDescriptor) []*apb.ResourceDescriptor

GetResourceDefinitions returns the google.api.resource_definition annotations for a file.

func GetResourceReference

func GetResourceReference(f *desc.FieldDescriptor) *apb.ResourceReference

GetResourceReference returns the google.api.resource_reference annotation.

func GetTypeName

func GetTypeName(f *desc.FieldDescriptor) string

GetTypeName returns the name of the type of the field, as a string, regardless of primitive, message, etc.

func IsCommonProto

func IsCommonProto(f *desc.FileDescriptor) bool

IsCommonProto returns true if a proto file is considered "common".

func IsDeclarativeFriendlyMessage

func IsDeclarativeFriendlyMessage(m *desc.MessageDescriptor) bool

IsDeclarativeFriendlyMessage returns true if the descriptor is declarative-friendly (if DeclarativeFriendlyResource(m) is not nil).

func IsDeclarativeFriendlyMethod

func IsDeclarativeFriendlyMethod(m *desc.MethodDescriptor) bool

IsDeclarativeFriendlyMethod returns true if the method is for a declarative-friendly resource (if DeclarativeFriendlyResource(m) is not nil).

func IsResource

func IsResource(m *desc.MessageDescriptor) bool

IsResource returns true if the message has a populated google.api.resource annotation with a non-empty "type" field.

func IsSingletonResource

func IsSingletonResource(m *desc.MessageDescriptor) bool

IsSingletonResource returns true if the given message is a singleton resource according to its pattern.

func LintFieldMask

func LintFieldMask(f *desc.FieldDescriptor) []lint.Problem

LintFieldMask returns a problem if the field is not a singular google.protobuf.FieldMask.

func LintFieldPresent

func LintFieldPresent(m *desc.MessageDescriptor, field string) (*desc.FieldDescriptor, []lint.Problem)

LintFieldPresent returns a problem if the given message does not have the given field.

func LintFieldPresentAndSingularString

func LintFieldPresentAndSingularString(field string) func(*desc.MessageDescriptor) []lint.Problem

LintFieldPresentAndSingularString returns a problem if a message does not have the given singular-string field.

func LintFieldResourceReference

func LintFieldResourceReference(f *desc.FieldDescriptor) []lint.Problem

LintFieldResourceReference returns a problem if the field does not have a resource reference annotation.

func LintHTTPMethod

func LintHTTPMethod(verb string) func(*desc.MethodDescriptor) []lint.Problem

LintHTTPMethod returns a problem for each HTTP rule whose HTTP method is not the given one.

func LintHTTPURIHasNameVariable

func LintHTTPURIHasNameVariable(m *desc.MethodDescriptor) []lint.Problem

LintHTTPURIHasNameVariable returns a problem if any of the given method's HTTP rules do not have a name variable in the URI.

func LintHTTPURIHasParentVariable

func LintHTTPURIHasParentVariable(m *desc.MethodDescriptor) []lint.Problem

LintHTTPURIHasParentVariable returns a problem if any of the given method's HTTP rules do not have a parent variable in the URI.

func LintHTTPURIHasVariable

func LintHTTPURIHasVariable(m *desc.MethodDescriptor, v string) []lint.Problem

LintHTTPURIHasVariable returns a problem if any of the given method's HTTP rules do not have the given variable in the URI.

func LintHTTPURIVariableCount

func LintHTTPURIVariableCount(m *desc.MethodDescriptor, n int) []lint.Problem

LintHTTPURIVariableCount returns a problem if the given method's HTTP rules do not contain the given number of variables in the URI.

func LintMethodHasMatchingRequestName

func LintMethodHasMatchingRequestName(m *desc.MethodDescriptor) []lint.Problem

LintMethodHasMatchingRequestName returns a problem if the given method's request type does not have a name matching the method's, with a "Request" suffix.

func LintMethodHasMatchingResponseName

func LintMethodHasMatchingResponseName(m *desc.MethodDescriptor) []lint.Problem

LintMethodHasMatchingResponseName returns a problem if the given method's response type does not have a name matching the method's, with a "Response" suffix.

func LintNoHTTPBody

func LintNoHTTPBody(m *desc.MethodDescriptor) []lint.Problem

LintNoHTTPBody returns a problem for each HTTP rule whose body is not "".

func LintOutputOnlyField

func LintOutputOnlyField(f *desc.FieldDescriptor) []lint.Problem

LintOutputOnlyField returns a problem if the field's behavior is not OUTPUT_ONLY.

func LintRequiredField

func LintRequiredField(f *desc.FieldDescriptor) []lint.Problem

LintRequiredField returns a problem if the field's behavior is not REQUIRED.

func LintSingularBoolField

func LintSingularBoolField(f *desc.FieldDescriptor) []lint.Problem

LintSingularBoolField returns a problem if the field is not a singular bool.

func LintSingularStringField

func LintSingularStringField(f *desc.FieldDescriptor) []lint.Problem

LintSingularStringField returns a problem if the field is not a singular string.

func LintWildcardHTTPBody

func LintWildcardHTTPBody(m *desc.MethodDescriptor) []lint.Problem

LintWildcardHTTPBody returns a problem for each HTTP rule whose body is not "*".

func ToPlural

func ToPlural(s string) string

ToPlural converts a string to its plural form.

func ToSingular

func ToSingular(s string) string

ToSingular converts a string to its singular form.

Types

type HTTPRule

type HTTPRule struct {
	// The HTTP method. Guaranteed to be in all caps.
	// This is set to "CUSTOM" if the Custom property is set.
	Method string

	// The HTTP URI (the value corresponding to the selected HTTP method).
	URI string

	// The `body` value forwarded from the generated proto's HttpRule.
	Body string

	// The `response_body` value forwarded from the generated proto's HttpRule.
	ResponseBody string
}

HTTPRule defines a parsed, easier-to-query equivalent to `apb.HttpRule`.

func GetHTTPRules

func GetHTTPRules(m *desc.MethodDescriptor) []*HTTPRule

GetHTTPRules returns a slice of HTTP rules for a given method descriptor.

Note: This returns a slice -- it takes the google.api.http annotation, and then flattens the values in `additional_bindings`. This allows rule authors to simply range over all of the HTTP rules, since the common case is to want to apply the checks to all of them.

func (*HTTPRule) GetPlainURI

func (h *HTTPRule) GetPlainURI() string

GetPlainURI returns the URI with variable segment information removed.

func (*HTTPRule) GetVariables

func (h *HTTPRule) GetVariables() map[string]string

GetVariables returns the variable segments in a URI as a map.

Jump to

Keyboard shortcuts

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