ir

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NamedType added in v0.2.6

func NamedType(goType string) string

NamedType returns goType when it is a bare type name rather than a builtin or a composite with no single referent.

func TypesByName added in v0.2.6

func TypesByName(types []*TypeDef) map[string]*TypeDef

TypesByName indexes type definitions by the Go name they declare.

Types

type APIInfo

type APIInfo struct {
	Title       string
	Version     string
	Description string
}

APIInfo contains metadata about the API.

type AuthScheme

type AuthScheme struct {
	Name        string // Identifier from the spec
	GoName      string // Go identifier
	Type        AuthType
	Description string
	// For APIKey:
	APIKeyName string // Header/query parameter name
	APIKeyIn   string // "header", "query", "cookie"
	// For HTTP Bearer:
	BearerFormat string
	// For OAuth2:
	OAuthFlows *OAuthFlowsDef
}

AuthScheme represents a security scheme from the spec.

type AuthType

type AuthType int

AuthType represents the type of authentication.

const (
	AuthTypeAPIKey AuthType = iota
	AuthTypeBearer
	AuthTypeBasic
	AuthTypeOAuth2
)

type DiscriminatorDef

type DiscriminatorDef struct {
	PropertyName string
	Mapping      map[string]string // discriminator value -> Go type name
}

DiscriminatorDef describes how to dispatch a union type.

type EnumVal

type EnumVal struct {
	Name    string // Go const name (e.g., PetStatusAvailable)
	Literal string // Rendered Go constant literal (quoted for strings)
}

EnumVal represents one value in an enum type.

type Field

type Field struct {
	Name                string // Go field name (PascalCase)
	JSONName            string // Original JSON property name (for struct tag)
	Type                string // Go type expression (e.g., "string", "*int64", "[]User")
	Description         string
	Required            bool
	IsPointer           bool // Whether to use pointer type (nullable or optional)
	OmitEmpty           bool // Whether to add omitempty to JSON tag
	Embedded            bool // Whether this is an embedded (anonymous) field
	Deprecated          bool
	ReadOnly            bool
	WriteOnly           bool
	PrimaryErrorMessage bool // Property annotated x-ms-primary-error-message
	CatchAll            bool // Synthetic field holding the schema's additionalProperties
}

Field represents a struct field.

type OAuthFlowDef

type OAuthFlowDef struct {
	AuthorizationURL string
	TokenURL         string
	RefreshURL       string
	Scopes           map[string]string // scope name -> description
}

OAuthFlowDef describes a single OAuth2 flow.

type OAuthFlowsDef

type OAuthFlowsDef struct {
	AuthorizationCode *OAuthFlowDef
	Implicit          *OAuthFlowDef
	ClientCredentials *OAuthFlowDef
	Password          *OAuthFlowDef
}

OAuthFlowsDef describes OAuth2 flows.

type OperationDef

type OperationDef struct {
	Name            string // Go method name (e.g., "ListUsers")
	Summary         string // Short summary from the spec
	Description     string
	HTTPMethod      string // "GET", "POST", etc.
	Path            string // URL path template (e.g., "/users/{id}")
	Tags            []string
	PathParams      []*ParamDef
	QueryParams     []*ParamDef
	HeaderParams    []*ParamDef
	CookieParams    []*ParamDef
	RequestBody     *RequestBodyDef // nil if no body
	Responses       []*ResponseDef
	SuccessResponse *ResponseDef    // The primary 2xx response
	ErrorResponses  []*ResponseDef  // 4xx/5xx responses
	SecurityReqs    [][]SecurityReq // OR of (AND of scheme refs)
	// NoAuth records that the operation declares an empty security requirement,
	// which overrides the document's to say it takes no credential.
	NoAuth bool
	// EventType is the Go type of one server-sent event's payload, set when a
	// success response offers text/event-stream.
	EventType  string
	Deprecated bool
	Pagination *PaginationDef // nil if not paginated
}

OperationDef represents a single API operation.

type Package

type Package struct {
	Name        string          // Go package name
	Types       []*TypeDef      // All type definitions
	Operations  []*OperationDef // All API operations
	AuthSchemes []*AuthScheme   // Security schemes from the spec
	Servers     []*ServerDef    // Servers the spec declares, in spec order
	Info        *APIInfo        // API title, version, description
	UserAgent   string          // Default User-Agent for generated clients
	Warnings    []string        // Spec constructs the generator could not act on
	Webhooks    []*WebhookDef   // Inbound payloads: webhooks and callbacks
}

Package is the top-level IR representing the entire generated package.

type PaginationDef

type PaginationDef struct {
	Style PaginationStyle
	// For cursor-based:
	CursorParam string // Query param name for the cursor
	CursorField string // Response field containing next cursor
	// For offset-based and page-based: the parameter that advances, and the one
	// that sizes a page.
	OffsetParam string
	LimitParam  string
	// Common:
	HasMoreField string // Response field indicating more pages exist (optional)
	TotalField   string // Response field with total count (optional)
	ItemsField   string // Response field containing the items array, empty when the response is the array
	ItemsType    string // Go element type of the items array (e.g., "Pet")
	// ItemsAreResponse marks a response that is the page rather than holding it.
	ItemsAreResponse bool
}

PaginationDef describes pagination for an operation.

type PaginationStyle

type PaginationStyle int

PaginationStyle represents the pagination strategy.

const (
	PaginationStyleCursor PaginationStyle = iota
	// PaginationStyleOffset advances by the number of items received.
	PaginationStyleOffset
	// PaginationStylePage advances by one page, whatever a page holds.
	PaginationStylePage
)

type ParamDef

type ParamDef struct {
	Name        string // Go parameter name (camelCase)
	FieldName   string // Go struct field name (PascalCase) for params struct
	OrigName    string // Original parameter name from spec
	Location    string // "path", "query", "header", "cookie"
	Type        string // Go type expression
	Required    bool
	Description string
	Deprecated  bool
	Style       string // serialization style
	Explode     bool
	ContentType string // Media type when the parameter is serialized with content rather than a style
	// AllowReserved sends RFC 3986 reserved characters through unescaped.
	AllowReserved bool
}

ParamDef represents an operation parameter.

type RequestBodyDef

type RequestBodyDef struct {
	Required    bool
	Description string
	ContentType string // Primary content type (e.g., "application/json")
	TypeName    string // Go type for the body
}

RequestBodyDef describes the request body.

type ResponseDef

type ResponseDef struct {
	StatusCode   string // "200", "404", "default", etc.
	Description  string
	ContentType  string
	TypeName     string // Go type for the response body (empty if no body)
	ErrorWrapper string // Go type name of the generated wrapper carrying the parsed body
	IsError      bool   // Whether this is an error response (4xx/5xx)
	Headers      []*ResponseHeaderDef
}

ResponseDef describes one response.

type ResponseHeaderDef

type ResponseHeaderDef struct {
	Name        string
	GoName      string
	Type        string // string, int64, float64, or bool
	Description string
	Required    bool
}

ResponseHeaderDef describes a response header.

type SecurityReq

type SecurityReq struct {
	SchemeName string
	Scopes     []string
}

SecurityReq represents a single security requirement.

type ServerDef added in v0.2.8

type ServerDef struct {
	URL         string
	Description string
	Variables   []*ServerVar // Template variables, in the order they appear in URL
}

ServerDef is one entry of the spec's servers list.

type ServerVar added in v0.2.8

type ServerVar struct {
	Name        string // Name as it appears in the URL template
	GoName      string // Go parameter name
	Default     string
	Enum        []string
	Description string
}

ServerVar is one template variable of a server URL.

type TypeDef

type TypeDef struct {
	Name          string            // Go type name (PascalCase)
	Description   string            // GoDoc comment
	Kind          TypeKind          // Struct, Alias, Enum, Union
	GoType        string            // For aliases: the underlying Go type string
	Fields        []*Field          // For structs
	EnumValues    []*EnumVal        // For enums
	EnumGoType    string            // For enums: the underlying Go type (e.g., "string", "int")
	UnionTypes    []*UnionVariant   // For oneOf/anyOf unions
	BaseType      string            // For unions: the type holding the properties every variant shares
	BaseEmbedded  bool              // For unions: whether the variants embed BaseType rather than declaring its fields
	Discriminator *DiscriminatorDef // If polymorphic via discriminator
	IsNullable    bool
}

TypeDef represents a Go type to be generated.

func StructNamed added in v0.2.6

func StructNamed(byName map[string]*TypeDef, goType string) *TypeDef

StructNamed returns the struct goType ultimately denotes, following the aliases that may stand between the two. It returns nil for anything that does not end at a generated struct.

type TypeKind

type TypeKind int

TypeKind represents the kind of Go type to generate.

const (
	TypeKindStruct TypeKind = iota
	TypeKindAlias
	TypeKindEnum
	TypeKindUnion
)

func (TypeKind) String

func (k TypeKind) String() string

String returns the string representation of a TypeKind.

type UnionVariant

type UnionVariant struct {
	TypeName           string // Go type name of this variant
	DiscriminatorValue string // For discriminator-based dispatch
}

UnionVariant represents one arm of a oneOf/anyOf union.

type WebhookDef added in v0.2.9

type WebhookDef struct {
	Name        string // Dispatch key: the webhook's name, or operation.callback
	GoName      string // Identifier fragment: Parse<GoName>Webhook
	Callback    bool   // Whether this came from an operation's callbacks
	Method      string // HTTP method the sender uses
	PayloadType string // Go type the body decodes into
	Description string
}

WebhookDef is one payload the API sends rather than receives: a webhook the document declares, or a callback an operation registers.

Jump to

Keyboard shortcuts

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