descriptor

package
v2.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsWellKnownType

func IsWellKnownType(typeName string) bool

IsWellKnownType returns true if the provided fully qualified type name is considered 'well-known'.

Types

type Binding

type Binding struct {
	// Method is the method which the endpoint is bound to.
	Method *Method
	// Index is a zero-origin index of the binding in the target method
	Index int
	// PathTmpl is path template where this method is mapped to.
	PathTmpl httprule.Template
	// HTTPMethod is the HTTP method which this method is mapped to.
	HTTPMethod string
	// PathParams is the list of parameters provided in HTTP request paths.
	PathParams []Parameter
	// Body describes parameters provided in HTTP request body.
	Body *Body
	// ResponseBody describes field in response struct to marshal in HTTP response body.
	ResponseBody *Body
}

Binding describes how an HTTP endpoint is bound to a gRPC method.

func (*Binding) ExplicitParams

func (b *Binding) ExplicitParams() []string

ExplicitParams returns a list of explicitly bound parameters of "b", i.e. a union of field path for body and field paths for path parameters.

type Body

type Body struct {
	// FieldPath is a path to a proto field which the (request|response) body is mapped to.
	// The (request|response) body is mapped to the (request|response) type itself if FieldPath is empty.
	FieldPath FieldPath
}

Body describes a http (request|response) body to be sent to the (method|client). This is used in body and response_body options in google.api.HttpRule

func (Body) AssignableExpr

func (b Body) AssignableExpr(msgExpr string) string

AssignableExpr returns an assignable expression in Go to be used to initialize method request object. It starts with "msgExpr", which is the go expression of the method request object.

type Enum

type Enum struct {
	*descriptorpb.EnumDescriptorProto
	// File is the file where the enum is defined
	File *File
	// Outers is a list of outer messages if this enum is a nested type.
	Outers []string
	// Index is a enum index value.
	Index int
	// ForcePrefixedName when set to true, prefixes a type with a package prefix.
	ForcePrefixedName bool
}

Enum describes a protocol buffer enum types.

func (*Enum) FQEN

func (e *Enum) FQEN() string

FQEN returns a fully qualified enum name of this enum.

func (*Enum) GoType

func (e *Enum) GoType(currentPackage string) string

GoType returns a go type name for the enum type. It prefixes the type name with the package alias if its belonging package is not "currentPackage".

type Field

type Field struct {
	*descriptorpb.FieldDescriptorProto
	// Message is the message type which this field belongs to.
	Message *Message
	// FieldMessage is the message type of the field.
	FieldMessage *Message
	// ForcePrefixedName when set to true, prefixes a type with a package prefix.
	ForcePrefixedName bool
}

Field wraps descriptorpb.FieldDescriptorProto for richer features.

func (*Field) FQFN

func (f *Field) FQFN() string

FQFN returns a fully qualified field name of this field.

type FieldPath

type FieldPath []FieldPathComponent

FieldPath is a path to a field from a request message.

func (FieldPath) AssignableExpr

func (p FieldPath) AssignableExpr(msgExpr string) string

AssignableExpr is an assignable expression in Go to be used to assign a value to the target field. It starts with "msgExpr", which is the go expression of the method request object.

func (FieldPath) IsNestedProto3

func (p FieldPath) IsNestedProto3() bool

IsNestedProto3 indicates whether the FieldPath is a nested Proto3 path.

func (FieldPath) IsOptionalProto3

func (p FieldPath) IsOptionalProto3() bool

IsOptionalProto3 indicates whether the FieldPath is a proto3 optional field.

func (FieldPath) String

func (p FieldPath) String() string

String returns a string representation of the field path.

type FieldPathComponent

type FieldPathComponent struct {
	// Name is a name of the proto field which this component corresponds to.
	// TODO(yugui) is this necessary?
	Name string
	// Target is the proto field which this component corresponds to.
	Target *Field
}

FieldPathComponent is a path component in FieldPath

func (FieldPathComponent) AssignableExpr

func (c FieldPathComponent) AssignableExpr() string

AssignableExpr returns an assignable expression in go for this field.

func (FieldPathComponent) ValueExpr

func (c FieldPathComponent) ValueExpr() string

ValueExpr returns an expression in go for this field.

type File

type File struct {
	*descriptorpb.FileDescriptorProto
	// GoPkg is the go package of the go file generated from this file.
	GoPkg GoPackage
	// GeneratedFilenamePrefix is used to construct filenames for generated
	// files associated with this source file.
	//
	// For example, the source file "dir/foo.proto" might have a filename prefix
	// of "dir/foo". Appending ".pb.go" produces an output file of "dir/foo.pb.go".
	GeneratedFilenamePrefix string
	// Messages is the list of messages defined in this file.
	Messages []*Message
	// Enums is the list of enums defined in this file.
	Enums []*Enum
	// Services is the list of services defined in this file.
	Services []*Service
}

File wraps descriptorpb.FileDescriptorProto for richer features.

func (*File) Pkg

func (f *File) Pkg() string

Pkg returns package name or alias if it's present

type GoPackage

type GoPackage struct {
	// Path is the package path to the package.
	Path string
	// Name is the package name of the package
	Name string
	// Alias is an alias of the package unique within the current invocation of gRPC-Gateway generator.
	Alias string
}

GoPackage represents a golang package.

func (GoPackage) Standard

func (p GoPackage) Standard() bool

Standard returns whether the import is a golang standard package.

func (GoPackage) String

func (p GoPackage) String() string

String returns a string representation of this package in the form of import line in golang.

type Message

type Message struct {
	*descriptorpb.DescriptorProto
	// File is the file where the message is defined.
	File *File
	// Outers is a list of outer messages if this message is a nested type.
	Outers []string
	// Fields is a list of message fields.
	Fields []*Field
	// Index is proto path index of this message in File.
	Index int
	// ForcePrefixedName when set to true, prefixes a type with a package prefix.
	ForcePrefixedName bool
}

Message describes a protocol buffer message types.

func (*Message) FQMN

func (m *Message) FQMN() string

FQMN returns a fully qualified message name of this message.

func (*Message) GoType

func (m *Message) GoType(currentPackage string) string

GoType returns a go type name for the message type. It prefixes the type name with the package alias if its belonging package is not "currentPackage".

type Method

type Method struct {
	*descriptorpb.MethodDescriptorProto
	// Service is the service which this method belongs to.
	Service *Service
	// RequestType is the message type of requests to this method.
	RequestType *Message
	// ResponseType is the message type of responses from this method.
	ResponseType *Message
	Bindings     []*Binding
}

Method wraps descriptorpb.MethodDescriptorProto for richer features.

func (*Method) FQMN

func (m *Method) FQMN() string

FQMN returns a fully qualified rpc method name of this method.

type Parameter

type Parameter struct {
	// FieldPath is a path to a proto field which this parameter is mapped to.
	FieldPath
	// Target is the proto field which this parameter is mapped to.
	Target *Field
	// Method is the method which this parameter is used for.
	Method *Method
}

Parameter is a parameter provided in http requests

func (Parameter) ConvertFuncExpr

func (p Parameter) ConvertFuncExpr() (string, error)

ConvertFuncExpr returns a go expression of a converter function. The converter function converts a string into a value for the parameter.

func (Parameter) IsEnum

func (p Parameter) IsEnum() bool

IsEnum returns true if the field is an enum type, otherwise false is returned.

func (Parameter) IsProto2

func (p Parameter) IsProto2() bool

IsProto2 returns true if the field is proto2, otherwise false is returned.

func (Parameter) IsRepeated

func (p Parameter) IsRepeated() bool

IsRepeated returns true if the field is repeated, otherwise false is returned.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is a registry of information extracted from pluginpb.CodeGeneratorRequest.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns a new Registry.

func (*Registry) AddExternalHTTPRule

func (r *Registry) AddExternalHTTPRule(qualifiedMethodName string, rule *annotations.HttpRule)

AddExternalHTTPRule adds an external http rule for the given fully qualified service method name

func (*Registry) AddPkgMap

func (r *Registry) AddPkgMap(file, protoPkg string)

AddPkgMap adds a mapping from a .proto file to proto package name.

func (*Registry) FieldName

func (r *Registry) FieldName(f *Field) string

func (*Registry) GetAllFQENs

func (r *Registry) GetAllFQENs() []string

GetAllFQENs returns a list of all FQENs

func (*Registry) GetAllFQMNs

func (r *Registry) GetAllFQMNs() []string

GetAllFQMNs returns a list of all FQMNs

func (*Registry) GetDisableDefaultErrors

func (r *Registry) GetDisableDefaultErrors() bool

GetDisableDefaultErrors returns disableDefaultErrors

func (*Registry) GetEnumsAsInts

func (r *Registry) GetEnumsAsInts() bool

GetEnumsAsInts returns enumsAsInts

func (*Registry) GetMergeFileName

func (r *Registry) GetMergeFileName() string

GetMergeFileName return the target merge OpenAPI file name

func (*Registry) GetOmitPackageDoc

func (r *Registry) GetOmitPackageDoc() bool

GetOmitPackageDoc returns whether a package comment will be omitted from the generated code

func (*Registry) GetOpenAPIFieldOption

func (r *Registry) GetOpenAPIFieldOption(qualifiedField string) (*options.JSONSchema, bool)

GetOpenAPIFieldOption returns a registered OpenAPI option for a field

func (*Registry) GetOpenAPIFileOption

func (r *Registry) GetOpenAPIFileOption(file string) (*options.Swagger, bool)

GetOpenAPIFileOption returns a registered OpenAPI option for a file

func (*Registry) GetOpenAPIMessageOption

func (r *Registry) GetOpenAPIMessageOption(qualifiedMessage string) (*options.Schema, bool)

GetOpenAPIMessageOption returns a registered OpenAPI option for a message

func (*Registry) GetOpenAPIMethodOption

func (r *Registry) GetOpenAPIMethodOption(qualifiedMethod string) (*options.Operation, bool)

GetOpenAPIMethodOption returns a registered OpenAPI option for a method

func (*Registry) GetOpenAPIServiceOption

func (r *Registry) GetOpenAPIServiceOption(qualifiedService string) (*options.Tag, bool)

GetOpenAPIServiceOption returns a registered OpenAPI option for a service

func (*Registry) GetProto3OptionalNullable

func (r *Registry) GetProto3OptionalNullable() bool

GetProto3OptionalNullable returns proto3OtionalNullable

func (*Registry) GetRecursiveDepth

func (r *Registry) GetRecursiveDepth() int

GetRecursiveDepth returns the max recursion count

func (*Registry) GetRepeatedPathParamSeparator

func (r *Registry) GetRepeatedPathParamSeparator() rune

GetRepeatedPathParamSeparator returns a rune spcifying how path parameter repeated fields are separated.

func (*Registry) GetRepeatedPathParamSeparatorName

func (r *Registry) GetRepeatedPathParamSeparatorName() string

GetRepeatedPathParamSeparatorName returns the name path parameter repeated fields repeatedFieldSeparator. I.e. 'csv', 'pipe', 'ssv' or 'tsv'

func (*Registry) GetSimpleOperationIDs

func (r *Registry) GetSimpleOperationIDs() bool

GetSimpleOperationIDs returns simpleOperationIDs

func (*Registry) GetUseFQNForOpenAPIName

func (r *Registry) GetUseFQNForOpenAPIName() bool

GetUseFQNForOpenAPIName returns useFQNForOpenAPIName

func (*Registry) GetUseGoTemplate

func (r *Registry) GetUseGoTemplate() bool

GetUseGoTemplate returns useGoTemplate

func (*Registry) GetUseJSONNamesForFields

func (r *Registry) GetUseJSONNamesForFields() bool

GetUseJSONNamesForFields returns useJSONNamesForFields

func (*Registry) IsAllowMerge

func (r *Registry) IsAllowMerge() bool

IsAllowMerge whether generation one OpenAPI file out of multiple protos

func (*Registry) IsAllowRepeatedFieldsInBody

func (r *Registry) IsAllowRepeatedFieldsInBody() bool

IsAllowRepeatedFieldsInBody checks if repeated field can be used in `body` and `response_body` (`google.api.http` annotation option) field path or not

func (*Registry) IsIncludePackageInTags

func (r *Registry) IsIncludePackageInTags() bool

IsIncludePackageInTags checks whether the package name defined in the `package` directive in the proto file can be prepended to the gRPC service name in the `Tags` field of every operation.

func (*Registry) Load

Load loads definitions of services, methods, messages, enumerations and fields from "req".

func (*Registry) LoadFromPlugin

func (r *Registry) LoadFromPlugin(gen *protogen.Plugin) error

func (*Registry) LoadGrpcAPIServiceFromYAML

func (r *Registry) LoadGrpcAPIServiceFromYAML(yamlFile string) error

LoadGrpcAPIServiceFromYAML loads a gRPC API Configuration from the given YAML file and registers the HttpRule descriptions contained in it as externalHTTPRules in the given registry. This must be done before loading the proto file.

You can learn more about gRPC API Service descriptions from google's documentation at https://cloud.google.com/endpoints/docs/grpc/grpc-service-config

Note that for the purposes of the gateway generator we only consider a subset of all available features google supports in their service descriptions.

func (*Registry) LoadOpenAPIConfigFromYAML

func (r *Registry) LoadOpenAPIConfigFromYAML(yamlFile string) error

LoadOpenAPIConfigFromYAML loads an OpenAPI Configuration from the given YAML file and registers the OpenAPI options the given registry. This must be done after loading the proto file.

func (*Registry) LookupEnum

func (r *Registry) LookupEnum(location, name string) (*Enum, error)

LookupEnum looks up a enum type by "name". It tries to resolve "name" from "location" if "name" is a relative enum name.

func (*Registry) LookupExternalHTTPRules

func (r *Registry) LookupExternalHTTPRules(qualifiedMethodName string) []*annotations.HttpRule

LookupExternalHTTPRules looks up external http rules by fully qualified service method name

func (*Registry) LookupFile

func (r *Registry) LookupFile(name string) (*File, error)

LookupFile looks up a file by name.

func (*Registry) LookupMsg

func (r *Registry) LookupMsg(location, name string) (*Message, error)

LookupMsg looks up a message type by "name". It tries to resolve "name" from "location" if "name" is a relative message name.

func (*Registry) RegisterOpenAPIOptions

func (r *Registry) RegisterOpenAPIOptions(opts *openapiconfig.OpenAPIOptions) error

RegisterOpenAPIOptions registers OpenAPI options

func (*Registry) ReserveGoPackageAlias

func (r *Registry) ReserveGoPackageAlias(alias, pkgpath string) error

ReserveGoPackageAlias reserves the unique alias of go package. If succeeded, the alias will be never used for other packages in generated go files. If failed, the alias is already taken by another package, so you need to use another alias for the package in your go files.

func (*Registry) SetAllowDeleteBody

func (r *Registry) SetAllowDeleteBody(allow bool)

SetAllowDeleteBody controls whether http delete methods may have a body or fail loading if encountered.

func (*Registry) SetAllowMerge

func (r *Registry) SetAllowMerge(allow bool)

SetAllowMerge controls whether generation one OpenAPI file out of multiple protos

func (*Registry) SetAllowRepeatedFieldsInBody

func (r *Registry) SetAllowRepeatedFieldsInBody(allow bool)

SetAllowRepeatedFieldsInBody controls whether repeated field can be used in `body` and `response_body` (`google.api.http` annotation option) field path or not

func (*Registry) SetDisableDefaultErrors

func (r *Registry) SetDisableDefaultErrors(use bool)

SetDisableDefaultErrors sets disableDefaultErrors

func (*Registry) SetEnumsAsInts

func (r *Registry) SetEnumsAsInts(enumsAsInts bool)

SetEnumsAsInts set enumsAsInts

func (*Registry) SetGenerateUnboundMethods

func (r *Registry) SetGenerateUnboundMethods(generate bool)

SetGenerateUnboundMethods sets generateUnboundMethods

func (*Registry) SetIncludePackageInTags

func (r *Registry) SetIncludePackageInTags(allow bool)

SetIncludePackageInTags controls whether the package name defined in the `package` directive in the proto file can be prepended to the gRPC service name in the `Tags` field of every operation.

func (*Registry) SetMergeFileName

func (r *Registry) SetMergeFileName(mergeFileName string)

SetMergeFileName controls the target OpenAPI file name out of multiple protos

func (*Registry) SetOmitPackageDoc

func (r *Registry) SetOmitPackageDoc(omit bool)

SetOmitPackageDoc controls whether the generated code contains a package comment (if set to false, it will contain one)

func (*Registry) SetPrefix

func (r *Registry) SetPrefix(prefix string)

SetPrefix registers the prefix to be added to go package paths generated from proto package names.

func (*Registry) SetProto3OptionalNullable

func (r *Registry) SetProto3OptionalNullable(proto3OtionalNullable bool)

SetProto3OptionalNullable set proto3OtionalNullable

func (*Registry) SetRecursiveDepth

func (r *Registry) SetRecursiveDepth(count int)

SetRecursiveDepth records the max recursion count

func (*Registry) SetRepeatedPathParamSeparator

func (r *Registry) SetRepeatedPathParamSeparator(name string) error

SetRepeatedPathParamSeparator sets how path parameter repeated fields are separated. Allowed names are 'csv', 'pipe', 'ssv' and 'tsv'.

func (*Registry) SetSimpleOperationIDs

func (r *Registry) SetSimpleOperationIDs(use bool)

SetSimpleOperationIDs sets simpleOperationIDs

func (*Registry) SetStandalone

func (r *Registry) SetStandalone(standalone bool)

SetStandalone registers standalone flag to control package prefix

func (*Registry) SetUseFQNForOpenAPIName

func (r *Registry) SetUseFQNForOpenAPIName(use bool)

SetUseFQNForOpenAPIName sets useFQNForOpenAPIName

func (*Registry) SetUseGoTemplate

func (r *Registry) SetUseGoTemplate(use bool)

SetUseGoTemplate sets useGoTemplate

func (*Registry) SetUseJSONNamesForFields

func (r *Registry) SetUseJSONNamesForFields(use bool)

SetUseJSONNamesForFields sets useJSONNamesForFields

func (*Registry) SetWarnOnUnboundMethods

func (r *Registry) SetWarnOnUnboundMethods(warn bool)

SetWarnOnUnboundMethods sets warnOnUnboundMethods

func (*Registry) UnboundExternalHTTPRules

func (r *Registry) UnboundExternalHTTPRules() []string

UnboundExternalHTTPRules returns the list of External HTTPRules which does not have a matching method in the registry

type ResponseFile

type ResponseFile struct {
	*pluginpb.CodeGeneratorResponse_File
	// GoPkg is the Go package of the generated file.
	GoPkg GoPackage
}

ResponseFile wraps pluginpb.CodeGeneratorResponse_File.

type Service

type Service struct {
	*descriptorpb.ServiceDescriptorProto
	// File is the file where this service is defined.
	File *File
	// Methods is the list of methods defined in this service.
	Methods []*Method
	// ForcePrefixedName when set to true, prefixes a type with a package prefix.
	ForcePrefixedName bool
}

Service wraps descriptorpb.ServiceDescriptorProto for richer features.

func (*Service) ClientConstructorName

func (s *Service) ClientConstructorName() string

ClientConstructorName returns name of the Client constructor with package prefix if needed

func (*Service) FQSN

func (s *Service) FQSN() string

FQSN returns the fully qualified service name of this service.

func (*Service) InstanceName

func (s *Service) InstanceName() string

InstanceName returns object name of the service with package prefix if needed

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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