ir

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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)
	Value any    // The actual enum value
}

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
}

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")
	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)
	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
	ServerURLs  []string        // Default server URLs
	Info        *APIInfo        // API title, version, description
}

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:
	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
	ItemsType    string // Go element type of the items array (e.g., "Pet")
}

PaginationDef describes pagination for an operation.

type PaginationStyle

type PaginationStyle int

PaginationStyle represents the pagination strategy.

const (
	PaginationStyleCursor PaginationStyle = iota
	PaginationStyleOffset
)

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
	Style       string // serialization style
	Explode     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
	IsMultipart bool
}

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)
	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
	Required bool
}

ResponseHeaderDef describes a response header.

type SecurityReq

type SecurityReq struct {
	SchemeName string
	Scopes     []string
}

SecurityReq represents a single security requirement.

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
	Discriminator *DiscriminatorDef // If polymorphic via discriminator
	IsNullable    bool
}

TypeDef represents a Go type to be generated.

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.

Jump to

Keyboard shortcuts

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