apienc

package
v1.41.3 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	QueryTag = tagDescription{
				// contains filtered or unexported fields
	}
	QsTag     = QueryTag
	HeaderTag = tagDescription{
				// contains filtered or unexported fields
	}
	JSONTag = tagDescription{
			// contains filtered or unexported fields
	}
	CookieTag = tagDescription{
				// contains filtered or unexported fields
	}
)
View Source
var (
	ErrFuncNotSupported = errRange.New(
		"Invalid API schema",
		"Functions are not supported in API schemas.",
	)

	ErrInterfaceNotSupported = errRange.New(
		"Invalid API schema",
		"Interfaces are not supported in API schemas.",
	)

	ErrAnonymousFieldsNotSupported = errRange.New(
		"Invalid API schema",
		"Anonymous fields are not supported in API schemas.",
	)
)

Functions

func IgnoreField

func IgnoreField(field schema.StructField) bool

IgnoreField returns true if the field name is "-" is any of the valid request or response tags

Types

type APIEncoding

type APIEncoding struct {
	DefaultMethod string `json:"default_method"`
	// Expresses how the default request encoding and method should be
	// Note: DefaultRequestEncoding.HTTPMethods will always be a slice with length 1
	DefaultRequestEncoding *RequestEncoding `json:"request_encoding"`
	// Expresses all the different ways the request can be encoded for this RPC
	RequestEncoding []*RequestEncoding `json:"all_request_encodings"`
	// Expresses how the response to this RPC will be encoded
	ResponseEncoding *ResponseEncoding `json:"response_encoding"`
}

APIEncoding expresses how an RPC should be encoded on the wire for both the request and responses.

func (*APIEncoding) RequestEncodingForMethod

func (e *APIEncoding) RequestEncodingForMethod(method string) *RequestEncoding

RequestEncodingForMethod returns the request encoding required for the given HTTP method. If the method is not supported by the RPC it reports nil.

type AuthEncoding

type AuthEncoding struct {
	// LegacyTokenFormat specifies whether the auth encoding uses the legacy format of
	// "just give us a token as a string". If true, the other parameters are all empty.
	LegacyTokenFormat bool

	// Contains metadata about how to marshal an HTTP parameter
	HeaderParameters []*ParameterEncoding `json:"header_parameters"`
	QueryParameters  []*ParameterEncoding `json:"query_parameters"`
	CookieParameters []*ParameterEncoding `json:"cookie_parameters"`
}

AuthEncoding expresses how a response should be encoded on the wire.

func DescribeAuth

func DescribeAuth(errs *perr.List, authSchema schema.Type) *AuthEncoding

DescribeAuth generates a ParameterEncoding per field of the auth struct and returns it as the AuthEncoding. If authSchema is nil it returns nil.

type ParameterEncoding

type ParameterEncoding struct {
	// SrcName is the name of the struct field
	SrcName string `json:"src_name"`
	// WireName is how the name is encoded on the wire.
	WireName string `json:"wire_name"`
	// Location is the location this encoding is for.
	Location WireLoc `json:"location"`
	// OmitEmpty specifies whether the parameter should be omitted if it's empty.
	OmitEmpty bool `json:"omit_empty"`
	// Doc is the documentation of the struct field
	Doc string `json:"doc"`
	// Type is the field's type description.
	Type schema.Type `json:"type"`
}

ParameterEncoding expresses how a parameter should be encoded on the wire

type RequestEncoding

type RequestEncoding struct {
	// The HTTP methods this encoding can be used for
	HTTPMethods []string `json:"http_methods"`
	// Contains metadata about how to marshal an HTTP parameter
	HeaderParameters []*ParameterEncoding `json:"header_parameters"`
	QueryParameters  []*ParameterEncoding `json:"query_parameters"`
	BodyParameters   []*ParameterEncoding `json:"body_parameters"`
}

RequestEncoding expresses how a request should be encoded for an explicit set of HTTPMethods

func DescribeRequest

func DescribeRequest(errs *perr.List, requestAST schema.Param, requestSchema schema.Type, methodsField option.Option[directive.Field], httpMethods ...string) []*RequestEncoding

DescribeRequest groups the provided httpMethods by default WireLoc and returns a RequestEncoding per WireLoc

func (*RequestEncoding) AllParameters added in v1.35.3

func (r *RequestEncoding) AllParameters() []*ParameterEncoding

type ResponseEncoding

type ResponseEncoding struct {
	// Contains metadata about how to marshal an HTTP parameter
	HeaderParameters []*ParameterEncoding `json:"header_parameters"`
	BodyParameters   []*ParameterEncoding `json:"body_parameters"`
}

ResponseEncoding expresses how a response should be encoded on the wire

func DescribeResponse

func DescribeResponse(errs *perr.List, responseSchema schema.Type) *ResponseEncoding

DescribeResponse generates a ParameterEncoding per field of the response struct and returns it as the ResponseEncoding

func (*ResponseEncoding) AllParameters added in v1.35.3

func (r *ResponseEncoding) AllParameters() []*ParameterEncoding

type WireLoc

type WireLoc string

WireLoc is the location of a parameter in the HTTP request/response.

const (
	Undefined WireLoc = "undefined" // Parameter location is undefined
	Header    WireLoc = "header"    // Parameter is placed in the HTTP header
	Query     WireLoc = "query"     // Parameter is placed in the query string
	Body      WireLoc = "body"      // Parameter is placed in the body
	Cookie    WireLoc = "cookie"    // Parameter is placed in cookies
)

Jump to

Keyboard shortcuts

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