Documentation ¶
Index ¶
- Variables
- func DeclarativeFriendlyResource(d desc.Descriptor) *desc.MessageDescriptor
- func FindFieldDotNotation(msg *desc.MessageDescriptor, ref string) *desc.FieldDescriptor
- func FindMessage(f *desc.FileDescriptor, name string) *desc.MessageDescriptor
- func FindMethod(f *desc.FileDescriptor, name string) *desc.MethodDescriptor
- func FindResource(reference string, file *desc.FileDescriptor) *apb.ResourceDescriptor
- func GetAllDependencies(file *desc.FileDescriptor) map[string]*desc.FileDescriptor
- func GetFieldBehavior(f *desc.FieldDescriptor) stringset.Set
- func GetListResourceMessage(m *desc.MethodDescriptor) *desc.MessageDescriptor
- func GetMetadataType(m *desc.MethodDescriptor) *desc.MessageDescriptor
- func GetMethodSignatures(m *desc.MethodDescriptor) [][]string
- func GetOperationInfo(m *desc.MethodDescriptor) *lrpb.OperationInfo
- func GetOperationResponseType(m *desc.MethodDescriptor) *desc.MessageDescriptor
- func GetRepeatedMessageFields(m *desc.MessageDescriptor) []*desc.FieldDescriptor
- func GetResource(m *desc.MessageDescriptor) *apb.ResourceDescriptor
- func GetResourceDefinitions(f *desc.FileDescriptor) []*apb.ResourceDescriptor
- func GetResourcePlural(r *apb.ResourceDescriptor) string
- func GetResourceReference(f *desc.FieldDescriptor) *apb.ResourceReference
- func GetResourceSingular(r *apb.ResourceDescriptor) string
- func GetResponseType(m *desc.MethodDescriptor) *desc.MessageDescriptor
- func GetTypeName(f *desc.FieldDescriptor) string
- func HasHTTPRules(m *desc.MethodDescriptor) bool
- func IsCommonProto(f *desc.FileDescriptor) bool
- func IsCreateMethod(m *desc.MethodDescriptor) bool
- func IsDeclarativeFriendlyMessage(m *desc.MessageDescriptor) bool
- func IsDeclarativeFriendlyMethod(m *desc.MethodDescriptor) bool
- func IsGetMethod(m *desc.MethodDescriptor) bool
- func IsListMethod(m *desc.MethodDescriptor) bool
- func IsListRevisionsMethod(m *desc.MethodDescriptor) bool
- func IsOperation(m *desc.MessageDescriptor) bool
- func IsResource(m *desc.MessageDescriptor) bool
- func IsSingletonResource(m *desc.MessageDescriptor) bool
- func IsUpdateMethod(m *desc.MethodDescriptor) bool
- func LintFieldMask(f *desc.FieldDescriptor) []lint.Problem
- func LintFieldPresent(m *desc.MessageDescriptor, field string) (*desc.FieldDescriptor, []lint.Problem)
- func LintFieldPresentAndSingularString(field string) func(*desc.MessageDescriptor) []lint.Problem
- func LintFieldResourceReference(f *desc.FieldDescriptor) []lint.Problem
- func LintHTTPMethod(verb string) func(*desc.MethodDescriptor) []lint.Problem
- func LintHTTPURIHasNameVariable(m *desc.MethodDescriptor) []lint.Problem
- func LintHTTPURIHasParentVariable(m *desc.MethodDescriptor) []lint.Problem
- func LintHTTPURIHasVariable(m *desc.MethodDescriptor, v string) []lint.Problem
- func LintHTTPURIVariableCount(m *desc.MethodDescriptor, n int) []lint.Problem
- func LintMethodHasMatchingRequestName(m *desc.MethodDescriptor) []lint.Problem
- func LintMethodHasMatchingResponseName(m *desc.MethodDescriptor) []lint.Problem
- func LintNoHTTPBody(m *desc.MethodDescriptor) []lint.Problem
- func LintNotOneof(f *desc.FieldDescriptor) []lint.Problem
- func LintOutputOnlyField(f *desc.FieldDescriptor) []lint.Problem
- func LintRequiredField(f *desc.FieldDescriptor) []lint.Problem
- func LintSingularBoolField(f *desc.FieldDescriptor) []lint.Problem
- func LintSingularField(f *desc.FieldDescriptor, t *builder.FieldType, want string) []lint.Problem
- func LintSingularStringField(f *desc.FieldDescriptor) []lint.Problem
- func LintWildcardHTTPBody(m *desc.MethodDescriptor) []lint.Problem
- func SeparateInternalComments(comments ...string) struct{ ... }
- func SplitResourceTypeName(typ string) (service string, typeName string, ok bool)
- func ToLowerCamelCase(s string) string
- func ToPlural(s string) string
- func ToSingular(s string) string
- func ToUpperCamelCase(s string) string
- type HTTPRule
Constants ¶
This section is empty.
Variables ¶
var ( // VersionedSegment is a regex to extract the API version from // an HTTP path. VersionedSegment = regexp.MustCompile(`\{\$api_version\}`) )
Functions ¶
func DeclarativeFriendlyResource ¶ added in v1.6.0
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 FindFieldDotNotation ¶ added in v1.36.2
func FindFieldDotNotation(msg *desc.MessageDescriptor, ref string) *desc.FieldDescriptor
FindFieldDotNotation returns a field descriptor from a given message that corresponds to the dot separated path e.g. "book.name". If the path is unresolable the method returns nil. This is especially useful for resolving path variables in google.api.http and nested fields in google.api.method_signature annotations.
func FindMessage ¶ added in v1.6.0
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 ¶ added in v1.6.0
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 FindResource ¶ added in v1.36.2
func FindResource(reference string, file *desc.FileDescriptor) *apb.ResourceDescriptor
FindResource returns first resource of type matching the reference param. resource Type name being referenced. It looks within a given file and its depenedencies, it cannot search within the entire protobuf package. This is especially useful for resolving google.api.resource_reference annotations.
func GetAllDependencies ¶ added in v1.21.0
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 GetListResourceMessage ¶ added in v1.48.0
func GetListResourceMessage(m *desc.MethodDescriptor) *desc.MessageDescriptor
GetListResourceMessage returns the resource for a list method, nil otherwise.
func GetMetadataType ¶ added in v1.32.3
func GetMetadataType(m *desc.MethodDescriptor) *desc.MessageDescriptor
GetMetadataType returns the message referred to by the (google.longrunning.operation_info).metadata_type annotation.
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 GetOperationResponseType ¶ added in v1.48.0
func GetOperationResponseType(m *desc.MethodDescriptor) *desc.MessageDescriptor
GetOperationResponseType returns the message referred to by the (google.longrunning.operation_info).response_type annotation.
func GetRepeatedMessageFields ¶ added in v1.31.0
func GetRepeatedMessageFields(m *desc.MessageDescriptor) []*desc.FieldDescriptor
GetRepeatedMessageFields returns all fields labeled `repeated` of type Message in the given message, sorted in field number order.
func GetResource ¶
func GetResource(m *desc.MessageDescriptor) *apb.ResourceDescriptor
GetResource returns the google.api.resource annotation.
func GetResourceDefinitions ¶ added in v1.1.0
func GetResourceDefinitions(f *desc.FileDescriptor) []*apb.ResourceDescriptor
GetResourceDefinitions returns the google.api.resource_definition annotations for a file.
func GetResourcePlural ¶ added in v1.49.0
func GetResourcePlural(r *apb.ResourceDescriptor) string
GetResourcePlural is a convenience method for getting the `plural` field of a resource.
func GetResourceReference ¶
func GetResourceReference(f *desc.FieldDescriptor) *apb.ResourceReference
GetResourceReference returns the google.api.resource_reference annotation.
func GetResourceSingular ¶ added in v1.49.0
func GetResourceSingular(r *apb.ResourceDescriptor) string
GetResourceSingular returns the resource singular. The empty string is returned if the singular cannot be found. Since the singular is not always annotated, it extracts it from multiple different locations including: 1. the singular annotation 2. the type definition
func GetResponseType ¶ added in v1.32.3
func GetResponseType(m *desc.MethodDescriptor) *desc.MessageDescriptor
GetResponseType returns the OutputType if the response is not an LRO, or the ResponseType otherwise.
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 HasHTTPRules ¶ added in v1.36.2
func HasHTTPRules(m *desc.MethodDescriptor) bool
HasHTTPRules returns true when the given method descriptor is annotated with a google.api.http option.
func IsCommonProto ¶
func IsCommonProto(f *desc.FileDescriptor) bool
IsCommonProto returns true if a proto file is considered "common".
func IsCreateMethod ¶ added in v1.48.0
func IsCreateMethod(m *desc.MethodDescriptor) bool
IsCreateMethod returns true if this is a AIP-133 Create method.
func IsDeclarativeFriendlyMessage ¶ added in v1.5.0
func IsDeclarativeFriendlyMessage(m *desc.MessageDescriptor) bool
IsDeclarativeFriendlyMessage returns true if the descriptor is declarative-friendly (if DeclarativeFriendlyResource(m) is not nil).
func IsDeclarativeFriendlyMethod ¶ added in v1.5.0
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 IsGetMethod ¶ added in v1.48.0
func IsGetMethod(m *desc.MethodDescriptor) bool
IsGetMethod returns true if this is a AIP-131 Get method.
func IsListMethod ¶ added in v1.48.0
func IsListMethod(m *desc.MethodDescriptor) bool
IsListMethod return true if this is an AIP-132 List method
func IsListRevisionsMethod ¶ added in v1.48.0
func IsListRevisionsMethod(m *desc.MethodDescriptor) bool
IsListRevisionsMethod returns true if this is an AIP-162 List Revisions method, false otherwise.
func IsOperation ¶ added in v1.45.0
func IsOperation(m *desc.MessageDescriptor) bool
IsOperation returns if the message is a longrunning Operation or not.
func IsResource ¶ added in v1.5.0
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 ¶ added in v1.21.0
func IsSingletonResource(m *desc.MessageDescriptor) bool
IsSingletonResource returns true if the given message is a singleton resource according to its pattern.
func IsUpdateMethod ¶ added in v1.48.0
func IsUpdateMethod(m *desc.MethodDescriptor) bool
IsUpdateMethod returns true if this is a AIP-134 Update method
func LintFieldMask ¶ added in v1.27.0
func LintFieldMask(f *desc.FieldDescriptor) []lint.Problem
LintFieldMask returns a problem if the field is not a singular google.protobuf.FieldMask.
func LintFieldPresent ¶ added in v1.13.0
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 ¶ added in v1.13.0
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 ¶ added in v1.7.0
func LintFieldResourceReference(f *desc.FieldDescriptor) []lint.Problem
LintFieldResourceReference returns a problem if the field does not have a resource reference annotation.
func LintHTTPMethod ¶ added in v1.7.0
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 ¶ added in v1.22.0
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 ¶ added in v1.20.0
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 ¶ added in v1.22.0
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 ¶ added in v1.26.0
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 ¶ added in v1.7.1
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 ¶ added in v1.17.0
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 ¶ added in v1.7.0
func LintNoHTTPBody(m *desc.MethodDescriptor) []lint.Problem
LintNoHTTPBody returns a problem for each HTTP rule whose body is not "".
func LintNotOneof ¶ added in v1.30.0
func LintNotOneof(f *desc.FieldDescriptor) []lint.Problem
LintNotOneof returns a problem if the field is a oneof.
func LintOutputOnlyField ¶ added in v1.21.0
func LintOutputOnlyField(f *desc.FieldDescriptor) []lint.Problem
LintOutputOnlyField returns a problem if the field's behavior is not OUTPUT_ONLY.
func LintRequiredField ¶ added in v1.7.0
func LintRequiredField(f *desc.FieldDescriptor) []lint.Problem
LintRequiredField returns a problem if the field's behavior is not REQUIRED.
func LintSingularBoolField ¶ added in v1.21.0
func LintSingularBoolField(f *desc.FieldDescriptor) []lint.Problem
LintSingularBoolField returns a problem if the field is not a singular bool.
func LintSingularField ¶ added in v1.30.0
LintSingularField returns a problem if the field is not singular i.e. it is repeated.
func LintSingularStringField ¶ added in v1.13.0
func LintSingularStringField(f *desc.FieldDescriptor) []lint.Problem
LintSingularStringField returns a problem if the field is not a singular string.
func LintWildcardHTTPBody ¶ added in v1.7.0
func LintWildcardHTTPBody(m *desc.MethodDescriptor) []lint.Problem
LintWildcardHTTPBody returns a problem for each HTTP rule whose body is not "*".
func SeparateInternalComments ¶ added in v1.50.0
SeparateInternalComments splits the given comment block into "external" and "internal" comments based on https://google.aip.dev/192#internal-comments.
func SplitResourceTypeName ¶ added in v1.43.0
SplitResourceTypeName splits the `Resource.type` field into the service name and the resource type name.
func ToLowerCamelCase ¶ added in v1.47.0
ToLowerCamelCase returns the lowerCamelCase of a string, including removing delimiters (_,-,., ) and using them to denote a new word.
func ToSingular ¶ added in v1.18.0
ToSingular converts a string to its singular form.
func ToUpperCamelCase ¶ added in v1.47.0
ToUpperCamelCase returns the UpperCamelCase of a string, including removing delimiters (_,-,., ) and using them to denote a new word.
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 ¶
GetPlainURI returns the URI with variable segment information removed.
func (*HTTPRule) GetVariables ¶
GetVariables returns the variable segments in a URI as a map.
For a given variable, the key is the variable's field path. The value is the variable's template, which will match segment(s) of the URL.
For more details on the path template syntax, see https://github.com/googleapis/googleapis/blob/6e1a5a066659794f26091674e3668229e7750052/google/api/http.proto#L224.