api

package
v0.0.0-...-6142172 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CrossReference

func CrossReference(model *API) error

CrossReference fills out the cross-references in `model` that the parser(s) missed.

The parsers cannot always cross-reference all elements because the elements are built incrementally, and may not be available until the parser has completed all the work.

This function is called after the parser has completed its work but before the codecs run. It populates links between the parsed elements that the codecs need. For example, the `oneof` fields use the containing `OneOf` to reference any types or names of the `OneOf` during their generation.

func LabelRecursiveFields

func LabelRecursiveFields(model *API)

func Validate

func Validate(model *API) error

Validate verifies the model satisfies the requires to be used by Codecs.

Types

type API

type API struct {
	// Name of the API (e.g. secretmanager).
	Name string
	// Name of the package name in the source specification format. For Protobuf
	// this may be `google.cloud.secretmanager.v1`.
	PackageName string
	// The API Title (e.g. "Secret Manager API" or "Cloud Spanner API").
	Title string
	// The API Description
	Description string
	// Services are a collection of services that make up the API.
	Services []*Service
	// Messages are a collection of messages used to process request and
	// responses in the API.
	Messages []*Message
	// Enums
	Enums []*Enum
	// Language specific annotations
	Codec any

	// State contains helpful information that can be used when generating
	// clients.
	State *APIState
}

API represents and API surface.

func NewTestAPI

func NewTestAPI(messages []*Message, enums []*Enum, services []*Service) *API

type APIState

type APIState struct {
	// ServiceByID returns a service that is associated with the API.
	ServiceByID map[string]*Service
	// MethodByID returns a method that is associated with the API.
	MethodByID map[string]*Method
	// MessageByID returns a message that is associated with the API.
	MessageByID map[string]*Message
	// EnumByID returns a message that is associated with the API.
	EnumByID map[string]*Enum
}

APIState contains helpful information that can be used when generating clients.

type Enum

type Enum struct {
	// Documentation for the message.
	Documentation string
	// Name of the attribute.
	Name string
	// ID is a unique identifier.
	ID string
	// Values associated with the Enum.
	Values []*EnumValue
	// Parent returns the ancestor of this node, if any.
	Parent *Message
	// The Protobuf package this enum belongs to.
	Package string
	// Language specific annotations.
	Codec any
}

Enum defines a message used in request/response handling.

func (*Enum) Scopes

func (x *Enum) Scopes() []string

type EnumValue

type EnumValue struct {
	// Documentation for the message.
	Documentation string
	// Name of the attribute.
	Name string
	// ID is a unique identifier.
	ID string
	// Number of the attribute.
	Number int32
	// Parent returns the ancestor of this node, if any.
	Parent *Enum
	// Language specific annotations.
	Codec any
}

EnumValue defines a value in an Enum.

func (*EnumValue) Scopes

func (x *EnumValue) Scopes() []string

type Field

type Field struct {
	// Documentation for the field.
	Documentation string
	// Name of the attribute.
	Name string
	// ID is a unique identifier.
	ID string
	// Typez is the datatype of the field.
	Typez Typez
	// TypezID is the ID of the type the field refers to. This value is populated
	// for message-like types only.
	TypezID string
	// JSONName is the name of the field as it appears in JSON. Useful for
	// serializing to JSON.
	JSONName string
	// Optional indicates that the field is marked as optional in proto3.
	Optional bool
	// Repeated is true if the field is a repeated field.
	Repeated bool
	// IsOneOf is true if the field is related to a one-of and not
	// a proto3 optional field.
	IsOneOf bool
	// The OpenAPI specifications have incomplete `*Request` messages. We inject
	// some helper fields. These need to be marked so they can be excluded
	// from serialized messages and in other places.
	Synthetic bool
	// Some fields have a type that refers (sometimes indirectly) to the
	// containing message. That triggers slightly different code generation for
	// some languages.
	Recursive bool
	// AutoPopulated is true if the field meets the requirements in AIP-4235.
	// That is:
	// - It has Typez == STRING_TYPE
	// - For Protobuf, has the `google.api.field_behavior = REQUIRED` annotation
	// - For Protobuf, has the `google.api.field_info.format = UUID4` annotation
	// - For OpenAPI, it is a required field
	// - For OpenAPI, it has format == "uuid"
	// - In the service config file, it is listed in the
	//   `google.api.MethodSettings.auto_populated_fields` entry in
	//   `google.api.Publishing.method_settings`
	AutoPopulated bool
	// For fields that are part of a OneOf, the group of fields that makes the
	// OneOf.
	Group *OneOf
	// A placeholder to put language specific annotations.
	Codec any
}

Field defines a field in a Message.

type Message

type Message struct {
	// Documentation for the message.
	Documentation string
	// Name of the attribute.
	Name string
	// ID is a unique identifier.
	ID string
	// Fields associated with the Message.
	Fields []*Field
	// IsLocalToPackage is true if the message is defined in the current
	// namespace.
	IsLocalToPackage bool
	// Enums associated with the Message.
	Enums []*Enum
	// Messages associated with the Message. In protobuf these are referred to as
	// nested messages.
	Messages []*Message
	// OneOfs associated with the Message.
	OneOfs []*OneOf
	// Parent returns the ancestor of this message, if any.
	Parent *Message
	// The Protobuf package this message belongs to.
	Package string
	IsMap   bool
	// IsPageableResponse indicated that this Message is returned by a standard
	// List RPC and conforms to [AIP-4233](https://google.aip.dev/client-libraries/4233).
	IsPageableResponse bool
	// PageableItem is the field to be paginated over.
	PageableItem *Field
	// Language specific annotations.
	Codec any
}

Message defines a message used in request/response handling.

func (*Message) Scopes

func (x *Message) Scopes() []string

type Method

type Method struct {
	// Documentation for the method.
	Documentation string
	// Name of the attribute.
	Name string
	// ID is a unique identifier.
	ID string
	// InputType is the input to the Method
	InputTypeID string
	InputType   *Message
	// OutputType is the output of the Method
	OutputTypeID string
	OutputType   *Message
	// PathInfo information about the HTTP request
	PathInfo *PathInfo
	// IsPageable is true if the method conforms to standard defined by
	// [AIP-4233](https://google.aip.dev/client-libraries/4233).
	IsPageable bool
	// The streaming attributes of the method. Bidi streaming methods have both
	// set to true.
	ClientSideStreaming bool
	ServerSideStreaming bool
	// For methods returning long-running operations
	OperationInfo *OperationInfo
	// The model this method belongs to, mustache templates use this field to
	// navigate the data structure.
	Model *API
	// The service this method belongs to, mustache templates use this field to
	// navigate the data structure.
	Service *Service
	// Language specific annotations
	Codec any
}

Method defines a RPC belonging to a Service.

type OneOf

type OneOf struct {
	// Name of the attribute.
	Name string
	// ID is a unique identifier.
	ID string
	// Documentation for the field.
	Documentation string
	// Fields associated with the one-of.
	Fields []*Field
	// A placeholder to put language specific annotations.
	Codec any
}

A group of fields that are mutually exclusive. Notably, proto3 optional fields are all their own one-of.

type OperationInfo

type OperationInfo struct {
	// The metadata type. If there is no metadata, this is set to
	// `.google.protobuf.Empty`.
	MetadataTypeID string
	// The result type. This is the expected type when the long running
	// operation completes successfully.
	ResponseTypeID string
	// The method.
	Method *Method
	// Language specific annotations
	Codec any
}

Normalized long running operation info

type Pair

type Pair struct {
	// Key of the pair.
	Key string
	// Value of the pair.
	Value string
}

Pair is a key-value pair.

type PathInfo

type PathInfo struct {
	// HTTP Verb.
	//
	// This is one of:
	// - GET
	// - POST
	// - PUT
	// - DELETE
	// - PATCH
	Verb string
	// The path broken by components.
	PathTemplate []PathSegment
	// Query parameter fields.
	QueryParameters map[string]bool
	// Body is the name of the field that should be used as the body of the
	// request.
	//
	// This is a string that may be "*" which indicates that the entire request
	// should be used as the body.
	//
	// If this is empty then the body is not used.
	BodyFieldPath string
	// Language specific annotations
	Codec any
}

Normalized request path information.

type PathSegment

type PathSegment struct {
	Literal   *string
	FieldPath *string
	Verb      *string
}

A path segment is either a string literal (such as "projects") or a field path (such as "options.version").

For OpenAPI these are formed by breaking the path string. Something like

`/v1/projects/{project}/secrets/{secret}:getIamPolicy`

should produce: ```

[]PathSegment{
  {Literal:   &"v1"},
  {Literal:   &"projects"},
  {FieldPath: &"project"},
  {Literal:   &"secrets"},
  {FieldPath: &"secret"},
  {Verb:      &"getIamPolicy"},
}

```

The Codec interpret these elements as needed.

func NewFieldPathPathSegment

func NewFieldPathPathSegment(s string) PathSegment

func NewLiteralPathSegment

func NewLiteralPathSegment(s string) PathSegment

func NewVerbPathSegment

func NewVerbPathSegment(s string) PathSegment

type Service

type Service struct {
	// Documentation for the service.
	Documentation string
	// Name of the attribute.
	Name string
	// ID is a unique identifier.
	ID string
	// Methods associated with the Service.
	Methods []*Method
	// DefaultHost fragment of a URL.
	DefaultHost string
	// The Protobuf package this service belongs to.
	Package string
	// The model this service belongs to, mustache templates use this field to
	// navigate the data structure.
	Model *API
	// Language specific annotations
	Codec any
}

Service represents a service in an API.

func (*Service) Scopes

func (x *Service) Scopes() []string

type Typez

type Typez int

Typez represent different field types that may be found in messages.

const (
	// These are the different field types as defined in
	// descriptorpb.FieldDescriptorProto_Type
	UNDEFINED_TYPE Typez = iota // 0
	DOUBLE_TYPE                 // 1
	FLOAT_TYPE                  // 2
	INT64_TYPE                  // 3
	UINT64_TYPE                 // 4
	INT32_TYPE                  // 5
	FIXED64_TYPE                // 6
	FIXED32_TYPE                // 7
	BOOL_TYPE                   // 8
	STRING_TYPE                 // 9
	GROUP_TYPE                  // 10
	MESSAGE_TYPE                // 11
	BYTES_TYPE                  // 12
	UINT32_TYPE                 // 13
	ENUM_TYPE                   // 14
	SFIXED32_TYPE               // 15
	SFIXED64_TYPE               // 16
	SINT32_TYPE                 // 17
	SINT64_TYPE                 // 18
)

Jump to

Keyboard shortcuts

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