transportir

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ResponseContractSuccess identifies a successful response contract case.
	ResponseContractSuccess ResponseContractCaseKind = "success"
	// ResponseContractError identifies an error response contract case.
	ResponseContractError ResponseContractCaseKind = "error"
	// ResponseContractHTTP identifies an ordinary HTTP response contract.
	ResponseContractHTTP ResponseContractTransport = "http"
	// ResponseContractSSE identifies a Server-Sent Events response contract.
	ResponseContractSSETransport ResponseContractTransport = "sse"
	// ResponseContractWebSocketTransport identifies a WebSocket response contract.
	ResponseContractWebSocketTransport ResponseContractTransport = "websocket"

	// ResponseContractMissingEndpoint indicates that no endpoint was supplied.
	ResponseContractMissingEndpoint ResponseContractLimitationCode = "missing_endpoint"
	// ResponseContractMissingIdentity indicates that a stable service or method
	// identity is unavailable.
	ResponseContractMissingIdentity ResponseContractLimitationCode = "missing_identity"
	// ResponseContractJSONRPC indicates that the endpoint uses JSON-RPC rather
	// than plain HTTP semantics.
	ResponseContractJSONRPC ResponseContractLimitationCode = "jsonrpc"
	// ResponseContractStreaming indicates that a streaming endpoint shape is
	// outside the supported SSE or WebSocket response contract scope.
	ResponseContractStreaming ResponseContractLimitationCode = "streaming"
	// ResponseContractRedirect indicates that the endpoint is a redirect.
	ResponseContractRedirect ResponseContractLimitationCode = "redirect"
	// ResponseContractMultipart indicates that request construction depends on
	// multipart handling outside the unary contract case.
	ResponseContractMultipart ResponseContractLimitationCode = "multipart"
	// ResponseContractRawRequestBody indicates that the service owns the raw
	// request body stream.
	ResponseContractRawRequestBody ResponseContractLimitationCode = "raw_request_body"
	// ResponseContractRawResponseBody indicates that the service owns the raw
	// response body stream.
	ResponseContractRawResponseBody ResponseContractLimitationCode = "raw_response_body"
	// ResponseContractDuplicateCaseID indicates that distinct response branches
	// produced the same stable identifier.
	ResponseContractDuplicateCaseID ResponseContractLimitationCode = "duplicate_case_id"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cookie struct {
	Name             string
	HTTPName         string
	Attribute        *expr.AttributeExpr
	Required         bool
	PrimitivePointer bool
	Path             string
	Domain           string
	MaxAge           string
	Secure           bool
	HTTPOnly         bool
	SameSite         expr.CookieSameSiteValue
}

type Endpoint

type Endpoint struct {
	Service        *Service
	Name           string
	MethodName     string
	Description    string
	Meta           expr.MetaExpr
	MethodMeta     expr.MetaExpr
	MethodDocs     *expr.DocsExpr
	Generate       bool
	MethodGenerate bool
	IsJSONRPC      bool
	Request        *Request
	Response       *Response
	Routes         []*Route
	Stream         *Stream
	Redirect       *Redirect
	Security       *Security
}

func BuildEndpoint

func BuildEndpoint(endpoint *expr.HTTPEndpointExpr) *Endpoint

type Error

type Error struct {
	Name      string
	Attribute *expr.AttributeExpr
	Type      expr.DataType
	Remedy    *ErrorRemedy
}

type ErrorRemedy

type ErrorRemedy struct {
	Code        string
	SafeMessage string
	RetryHint   string
}
type Header struct {
	Name             string
	HTTPName         string
	Attribute        *expr.AttributeExpr
	Required         bool
	PrimitivePointer bool
}

type Parameter

type Parameter struct {
	Name             string
	HTTPName         string
	In               string
	Attribute        *expr.AttributeExpr
	Required         bool
	PrimitivePointer bool
	Map              bool
	MapQueryParams   *string
	StringSlice      bool
	Slice            bool
}

type Redirect

type Redirect struct {
	URL        string
	StatusCode int
}

type Request

type Request struct {
	Payload *expr.AttributeExpr
	Body    *expr.AttributeExpr
	RawBody *expr.AttributeExpr
	// DocumentBody is the documentation-only request body schema.
	DocumentBody *expr.AttributeExpr
	// DocumentContentTypes are the documentation-only request media types.
	DocumentContentTypes []string
	// DocumentRequired is the documentation-only request body requiredness.
	DocumentRequired    bool
	StreamingBody       *expr.AttributeExpr
	BodyOrigin          string
	PathParams          []*Parameter
	QueryParams         []*Parameter
	Headers             []*Parameter
	Cookies             []*Parameter
	MapQueryParams      *string
	Multipart           bool
	FormEncoded         bool
	OptionalBody        bool
	MustHaveBody        bool
	SkipBodyEncode      bool
	IDAttribute         string
	IDAttributeRequired bool
}

type Response

type Response struct {
	Result              *expr.AttributeExpr
	StreamingResult     *expr.AttributeExpr
	Responses           []*ResponseStatus
	ErrorResponses      []*ResponseStatus
	HasMixedResults     bool
	SkipBodyEncode      bool
	FileResponse        bool
	IDAttribute         string
	IDAttributeRequired bool
}

type ResponseContractAnalysis added in v1.8.0

type ResponseContractAnalysis struct {
	// Cases lists the declared response branches in design order.
	Cases []*ResponseContractCase
	// Limitations explains why cases could not be produced.
	Limitations []ResponseContractLimitation
}

ResponseContractAnalysis describes the exhaustive response cases for a supported HTTP endpoint. Cases is empty when Limitations is not.

func AnalyzeResponseContractCases added in v1.8.0

func AnalyzeResponseContractCases(endpoint *Endpoint) *ResponseContractAnalysis

AnalyzeResponseContractCases builds deterministic, exhaustive descriptors for the declared response branches of a supported HTTP endpoint.

func (*ResponseContractAnalysis) Supported added in v1.8.0

func (a *ResponseContractAnalysis) Supported() bool

Supported reports whether the endpoint is inside the HTTP response contract analysis scope.

type ResponseContractCase added in v1.8.0

type ResponseContractCase struct {
	// ID is stable across generation when the service contract is unchanged.
	ID string
	// Kind distinguishes successful results from service errors.
	Kind ResponseContractCaseKind
	// Transport identifies the response protocol.
	Transport ResponseContractTransport
	// StatusCode is the declared HTTP response status.
	StatusCode int
	// ErrorName is the declared service error name for error cases.
	ErrorName string
	// TagName is the result field selecting a tagged success response.
	TagName string
	// TagValue is the result field value selecting a tagged success response.
	TagValue string
	// ContentTypes lists the declared response media types.
	ContentTypes []string
	// HasBody reports whether the response contract asserts a body media type.
	HasBody bool
	// Headers lists the declared response header assertions.
	Headers []ResponseContractHeader
	// Cookies lists the declared response cookie assertions.
	Cookies []ResponseContractCookie
	// Multipart describes the designed multipart request, if present.
	Multipart *ResponseContractMultipartRequest
	// SSE describes stream assertions for an SSE success case.
	SSE *ResponseContractSSE
	// WebSocket describes stream assertions for a WebSocket success case.
	WebSocket *ResponseContractWebSocket
}

ResponseContractCase describes one declared HTTP response branch.

type ResponseContractCaseKind added in v1.8.0

type ResponseContractCaseKind string

ResponseContractCaseKind identifies whether a contract case exercises a successful result or a service error.

type ResponseContractCookie added in v1.8.0

type ResponseContractCookie struct {
	// Name is the result or error attribute mapped to the cookie.
	Name string
	// HTTPName is the wire cookie name.
	HTTPName string
	// Required reports whether the mapped attribute is required.
	Required bool
	// Path is the declared cookie Path attribute.
	Path string
	// Domain is the declared cookie Domain attribute.
	Domain string
	// MaxAge is the declared cookie Max-Age attribute.
	MaxAge string
	// Secure reports whether the cookie is restricted to secure transports.
	Secure bool
	// HTTPOnly reports whether scripts are denied cookie access.
	HTTPOnly bool
	// SameSite is the declared cookie SameSite policy.
	SameSite expr.CookieSameSiteValue
}

ResponseContractCookie describes a declared response cookie assertion.

type ResponseContractHeader added in v1.8.0

type ResponseContractHeader struct {
	// Name is the result or error attribute mapped to the header.
	Name string
	// HTTPName is the wire header name.
	HTTPName string
	// Required reports whether the mapped attribute is required.
	Required bool
}

ResponseContractHeader describes a declared response header assertion.

type ResponseContractLimitation added in v1.8.0

type ResponseContractLimitation struct {
	// Code identifies the unsupported endpoint feature.
	Code ResponseContractLimitationCode
	// Detail explains the limitation for diagnostics.
	Detail string
}

ResponseContractLimitation explains why an endpoint is outside the response contract analysis scope.

type ResponseContractLimitationCode added in v1.8.0

type ResponseContractLimitationCode string

ResponseContractLimitationCode identifies an endpoint feature that the HTTP response contract analysis intentionally does not support.

type ResponseContractMultipartPart added in v1.8.0

type ResponseContractMultipartPart struct {
	// Name is the multipart form field name.
	Name string
	// MediaType is the default media type for the part value.
	MediaType string
	// Required reports whether the request body requires the part.
	Required bool
}

ResponseContractMultipartPart describes one designed multipart field.

type ResponseContractMultipartRequest added in v1.8.0

type ResponseContractMultipartRequest struct {
	// ContentType is the request media type.
	ContentType string
	// Parts lists the designed multipart fields in body order.
	Parts []ResponseContractMultipartPart
}

ResponseContractMultipartRequest describes a multipart request shape that can be represented without an application-owned codec.

type ResponseContractSSE added in v1.8.0

type ResponseContractSSE struct {
	// Direction is the designed stream direction.
	Direction string
	// MessageType is the designed streaming result type name.
	MessageType string
	// DataField is the result field encoded into SSE data, if any.
	DataField string
	// DataEncoding identifies whether SSE data is JSON or plain text.
	DataEncoding string
	// IDField is the result field encoded into SSE id, if any.
	IDField string
	// EventField is the result field encoded into SSE event, if any.
	EventField string
	// RetryField is the result field encoded into SSE retry, if any.
	RetryField string
	// IDRequired reports whether every observed event must include an ID.
	IDRequired bool
	// EventTypeRequired reports whether every observed event must include a type.
	EventTypeRequired bool
	// EventTypes lists allowed projection discriminator values, if constrained.
	EventTypes []string
	// Terminal identifies the expected stream completion behavior.
	Terminal string
}

ResponseContractSSE describes a generated Server-Sent Events contract.

type ResponseContractTransport added in v1.8.0

type ResponseContractTransport string

ResponseContractTransport identifies the wire protocol validated by a response contract case.

type ResponseContractWebSocket added in v1.8.0

type ResponseContractWebSocket struct {
	// Direction is the designed stream direction.
	Direction string
	// InboundMessageType is the designed client-to-server message type name.
	InboundMessageType string
	// OutboundMessageType is the designed server-to-client message type name.
	OutboundMessageType string
	// HandshakeHeaders lists required WebSocket upgrade response headers.
	HandshakeHeaders []string
	// Terminal identifies the expected stream completion behavior.
	Terminal string
}

ResponseContractWebSocket describes a generated WebSocket contract.

type ResponseLink struct {
	Name         string
	Operation    string
	OperationRef string
	Description  string
	RequestBody  string
	Parameters   map[string]string
}

type ResponseStatus

type ResponseStatus struct {
	Error        *Error
	StatusCode   int
	Description  string
	ContentType  string
	ContentTypes []string
	Headers      []*Header
	Cookies      []*Cookie
	Body         *expr.AttributeExpr
	DocumentBody *expr.AttributeExpr
	BodyOrigin   string
	TagName      string
	TagValue     string
	IsError      bool
	EmitExamples bool
	IsWebSocket  bool
	BinaryBody   bool
	Meta         expr.MetaExpr
	Links        []*ResponseLink
}

type Route

type Route struct {
	Index      int
	Method     string
	Path       string
	SourcePath string
	Wildcards  []string
}

func RouteForExpr

func RouteForExpr(endpoint *Endpoint, route *expr.RouteExpr, renderedPath string) *Route

type SSE

type SSE struct {
	RequestIDField     string
	RequestIDPointer   bool
	NotificationMethod string
	DataField          string
	IDField            string
	EventField         string
	RetryField         string
	Projections        []*expr.SSEProjectionExpr
}

type Security

type Security struct {
	Requirements []*expr.SecurityExpr
	Parameters   []*SecurityParameter
	Disabled     bool
}

type SecurityParameter

type SecurityParameter struct {
	Name       string
	In         string
	SchemeName string
}

type Service

type Service struct {
	Name            string
	Meta            expr.MetaExpr
	ServiceMeta     expr.MetaExpr
	Generate        bool
	ServiceGenerate bool
	Endpoints       []*Endpoint
}

func BuildService

func BuildService(service *expr.HTTPServiceExpr) *Service

type Stream

type Stream struct {
	Kind             expr.StreamKind
	Direction        string
	IsStreaming      bool
	Transport        string
	IsSSE            bool
	IsWebSocket      bool
	HasMixedResults  bool
	RequestHasBody   bool
	RequestPayload   *expr.AttributeExpr
	RequestMessage   *expr.AttributeExpr
	ResponseMessage  *expr.AttributeExpr
	HandshakeMethod  string
	HandshakeStatus  int
	HandshakeContent string
	SSE              *SSE
}

Jump to

Keyboard shortcuts

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