Documentation
¶
Index ¶
- func EnsureDirectory(path string) error
- func FileExists(path string) bool
- func FormatCode(code string, language string) string
- func GenerateSSEClientName(endpoint SSEEndpoint) string
- func GenerateStreamingFeatureDocs(features Features) string
- func GenerateWebSocketClientName(endpoint WebSocketEndpoint) string
- func GetStreamingEndpointCount(spec *APISpec) (websockets, sse int)
- func HasSSE(spec *APISpec) bool
- func HasStreamingEndpoints(spec *APISpec) bool
- func HasWebSockets(spec *APISpec) bool
- func NeedsAuthConfig(spec *APISpec) bool
- type APIInfo
- type APISpec
- type APIStats
- type AuthCodeGenerator
- func (a *AuthCodeGenerator) DetectAuthSchemes(spec *APISpec) []DetectedAuthScheme
- func (a *AuthCodeGenerator) GenerateAuthDocumentation(schemes []DetectedAuthScheme) string
- func (a *AuthCodeGenerator) GetAuthConfigType(schemes []DetectedAuthScheme) string
- func (a *AuthCodeGenerator) GetAuthHeaderName(scheme DetectedAuthScheme) string
- func (a *AuthCodeGenerator) GetAuthPrefix(scheme DetectedAuthScheme) string
- func (a *AuthCodeGenerator) GetEndpointAuthRequirements(endpoint Endpoint, spec *APISpec) []AuthRequirement
- type AuthRequirement
- type BackoffCalculator
- type ConnectionState
- type Contact
- type DetectedAuthScheme
- type Discriminator
- type Endpoint
- type EndpointType
- type Example
- type Features
- type Generator
- func (g *Generator) Generate(ctx context.Context, spec *APISpec, config GeneratorConfig) (*generators.GeneratedClient, error)
- func (g *Generator) GenerateFromFile(ctx context.Context, filePath string, config GeneratorConfig) (*generators.GeneratedClient, error)
- func (g *Generator) GenerateFromRouter(ctx context.Context, r any, config GeneratorConfig) (*generators.GeneratedClient, error)
- func (g *Generator) GetGeneratorInfo(language string) (GeneratorInfo, error)
- func (g *Generator) ListGenerators() []string
- func (g *Generator) Register(gen generators.LanguageGenerator) error
- type GeneratorConfig
- type GeneratorInfo
- type GeneratorOption
- func WithAPIName(name string) GeneratorOption
- func WithAuth(enabled bool) GeneratorOption
- func WithBaseURL(url string) GeneratorOption
- func WithFeatures(features Features) GeneratorOption
- func WithLanguage(lang string) GeneratorOption
- func WithModule(module string) GeneratorOption
- func WithOutputDir(dir string) GeneratorOption
- func WithPackageName(name string) GeneratorOption
- func WithStreaming(enabled bool) GeneratorOption
- func WithVersion(version string) GeneratorOption
- type HeartbeatConfig
- type Introspector
- type License
- type MediaType
- type OAuthFlow
- type OAuthFlows
- type OutputManager
- type Parameter
- type ReconnectionConfig
- type ReconnectionStrategy
- type RequestBody
- type Response
- type SSEClientTemplate
- type SSEEndpoint
- type Schema
- type SecurityRequirement
- type SecurityScheme
- type Server
- type ServerVariable
- type SpecParser
- type StreamSchema
- type StreamingCodeHelper
- type StreamingFeatures
- type Tag
- type ValidationError
- type ValidationOptions
- type WebSocketClientTemplate
- type WebSocketEndpoint
- type WebTransportEndpoint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureDirectory ¶
EnsureDirectory ensures a directory exists.
func FormatCode ¶
FormatCode formats generated code (basic formatting).
func GenerateSSEClientName ¶
func GenerateSSEClientName(endpoint SSEEndpoint) string
GenerateSSEClientName generates a name for an SSE client struct/class.
func GenerateStreamingFeatureDocs ¶
GenerateStreamingFeatureDocs generates documentation for streaming features.
func GenerateWebSocketClientName ¶
func GenerateWebSocketClientName(endpoint WebSocketEndpoint) string
GenerateWebSocketClientName generates a name for a WebSocket client struct/class.
func GetStreamingEndpointCount ¶
GetStreamingEndpointCount returns the count of streaming endpoints.
func HasStreamingEndpoints ¶
HasStreamingEndpoints checks if the API spec has any streaming endpoints.
func HasWebSockets ¶
HasWebSockets checks if the API spec has WebSocket endpoints.
func NeedsAuthConfig ¶
NeedsAuthConfig determines if any endpoints need authentication.
Types ¶
type APIInfo ¶
type APIInfo struct {
Title string
Version string
Description string
Contact *Contact
License *License
}
APIInfo contains metadata about the API.
type APISpec ¶
type APISpec struct {
Info APIInfo
Servers []Server
Endpoints []Endpoint
WebSockets []WebSocketEndpoint
SSEs []SSEEndpoint
WebTransports []WebTransportEndpoint
Schemas map[string]*Schema
Security []SecurityScheme
Tags []Tag
}
APISpec represents the complete API specification in an intermediate representation.
func (*APISpec) ResolveSchemaRef ¶
ResolveSchemaRef resolves a schema reference in the spec.
func (*APISpec) Validate ¶
func (spec *APISpec) Validate(opts ValidationOptions) []ValidationError
Validate validates the API spec.
type APIStats ¶
type APIStats struct {
TotalEndpoints int
RESTEndpoints int
WebSocketCount int
SSECount int
SecuredEndpoints int
Tags []string
UpdatedAt time.Time
}
Stats returns statistics about the API spec.
type AuthCodeGenerator ¶
type AuthCodeGenerator struct{}
AuthCodeGenerator generates authentication-related code.
func NewAuthCodeGenerator ¶
func NewAuthCodeGenerator() *AuthCodeGenerator
NewAuthCodeGenerator creates a new auth code generator.
func (*AuthCodeGenerator) DetectAuthSchemes ¶
func (a *AuthCodeGenerator) DetectAuthSchemes(spec *APISpec) []DetectedAuthScheme
DetectAuthSchemes detects authentication schemes from the API spec.
func (*AuthCodeGenerator) GenerateAuthDocumentation ¶
func (a *AuthCodeGenerator) GenerateAuthDocumentation(schemes []DetectedAuthScheme) string
GenerateAuthDocumentation generates documentation for authentication.
func (*AuthCodeGenerator) GetAuthConfigType ¶
func (a *AuthCodeGenerator) GetAuthConfigType(schemes []DetectedAuthScheme) string
GetAuthConfigType determines the appropriate auth config type.
func (*AuthCodeGenerator) GetAuthHeaderName ¶
func (a *AuthCodeGenerator) GetAuthHeaderName(scheme DetectedAuthScheme) string
GetAuthHeaderName returns the header name for an auth scheme.
func (*AuthCodeGenerator) GetAuthPrefix ¶
func (a *AuthCodeGenerator) GetAuthPrefix(scheme DetectedAuthScheme) string
GetAuthPrefix returns the prefix for an auth value (e.g., "Bearer ").
func (*AuthCodeGenerator) GetEndpointAuthRequirements ¶
func (a *AuthCodeGenerator) GetEndpointAuthRequirements(endpoint Endpoint, spec *APISpec) []AuthRequirement
GetEndpointAuthRequirements returns auth requirements for an endpoint.
type AuthRequirement ¶
AuthRequirement represents an authentication requirement for a specific endpoint.
type BackoffCalculator ¶
type BackoffCalculator struct {
// contains filtered or unexported fields
}
BackoffCalculator calculates backoff delays.
func NewBackoffCalculator ¶
func NewBackoffCalculator(config ReconnectionConfig) *BackoffCalculator
NewBackoffCalculator creates a new backoff calculator.
type ConnectionState ¶
type ConnectionState string
ConnectionState represents the state of a streaming connection.
const ( // ConnectionStateDisconnected means not connected. ConnectionStateDisconnected ConnectionState = "disconnected" // ConnectionStateConnecting means attempting to connect. ConnectionStateConnecting ConnectionState = "connecting" // ConnectionStateConnected means successfully connected. ConnectionStateConnected ConnectionState = "connected" // ConnectionStateReconnecting means attempting to reconnect. ConnectionStateReconnecting ConnectionState = "reconnecting" // ConnectionStateClosed means connection is closed and won't reconnect. ConnectionStateClosed ConnectionState = "closed" // ConnectionStateError means connection error occurred. ConnectionStateError ConnectionState = "error" )
type DetectedAuthScheme ¶
type DetectedAuthScheme struct {
Name string
Type string
In string
Scheme string
BearerFormat string
RequiresScope bool
}
DetectedAuthScheme represents a detected authentication scheme.
func MergeAuthSchemes ¶
func MergeAuthSchemes(schemes []DetectedAuthScheme) []DetectedAuthScheme
MergeAuthSchemes merges authentication schemes, removing duplicates.
type Discriminator ¶
type Discriminator struct {
PropertyName string
Mapping map[string]string // value -> schema reference
}
Discriminator supports polymorphism.
type Endpoint ¶
type Endpoint struct {
ID string
Method string
Path string
Summary string
Description string
Tags []string
OperationID string
Deprecated bool
// Parameters
PathParams []Parameter
QueryParams []Parameter
HeaderParams []Parameter
// Request/Response
RequestBody *RequestBody
Responses map[int]*Response
DefaultError *Response
// Security
Security []SecurityRequirement
// Metadata
Metadata map[string]any
}
Endpoint represents a REST API endpoint.
func (*Endpoint) GetType ¶
func (e *Endpoint) GetType() EndpointType
GetEndpointType returns the type of endpoint.
type EndpointType ¶
type EndpointType string
EndpointType represents the type of endpoint.
const ( EndpointTypeREST EndpointType = "REST" EndpointTypeWebSocket EndpointType = "WebSocket" EndpointTypeSSE EndpointType = "SSE" EndpointTypeWebTransport EndpointType = "WebTransport" )
type Features ¶
type Features struct {
// Reconnection enables automatic reconnection for streaming endpoints
Reconnection bool
// Heartbeat enables heartbeat/ping for maintaining connections
Heartbeat bool
// StateManagement enables connection state tracking
StateManagement bool
// TypedErrors generates typed error responses
TypedErrors bool
// RequestRetry enables automatic request retry with exponential backoff
RequestRetry bool
// Timeout enables request timeout configuration
Timeout bool
// Middleware enables request/response middleware/interceptors
Middleware bool
// Logging enables built-in logging support
Logging bool
}
Features contains feature flags for client generation.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator orchestrates client code generation.
func DefaultGenerator ¶
func DefaultGenerator() *Generator
DefaultGenerator returns a generator with all built-in generators registered.
func NewGenerator ¶
func NewGenerator() *Generator
NewGenerator creates a new generator with registered language generators.
func (*Generator) Generate ¶
func (g *Generator) Generate(ctx context.Context, spec *APISpec, config GeneratorConfig) (*generators.GeneratedClient, error)
Generate generates a client for the specified language.
func (*Generator) GenerateFromFile ¶
func (g *Generator) GenerateFromFile(ctx context.Context, filePath string, config GeneratorConfig) (*generators.GeneratedClient, error)
GenerateFromFile generates a client from a spec file.
func (*Generator) GenerateFromRouter ¶
func (g *Generator) GenerateFromRouter(ctx context.Context, r any, config GeneratorConfig) (*generators.GeneratedClient, error)
GenerateFromRouter generates a client by introspecting a router.
func (*Generator) GetGeneratorInfo ¶
func (g *Generator) GetGeneratorInfo(language string) (GeneratorInfo, error)
GetGeneratorInfo returns information about a specific generator.
func (*Generator) ListGenerators ¶
ListGenerators returns all registered generators.
func (*Generator) Register ¶
func (g *Generator) Register(gen generators.LanguageGenerator) error
Register registers a language generator.
type GeneratorConfig ¶
type GeneratorConfig struct {
// Language specifies the target language (go, typescript, rust)
Language string
// OutputDir is the directory where generated files will be written
OutputDir string
// PackageName is the name of the generated package/module
PackageName string
// APIName is the name of the main client struct/class
APIName string
// BaseURL is the default base URL for the API
BaseURL string
// IncludeAuth determines if auth configuration should be generated
IncludeAuth bool
// IncludeStreaming determines if WebSocket/SSE clients should be generated
IncludeStreaming bool
// Features contains feature flags for generation
Features Features
// Module is the Go module path (for Go only)
Module string
// Version is the version of the generated client
Version string
// Enhanced features
UseFetch bool // Use fetch instead of axios (TypeScript)
DualPackage bool // Generate ESM + CJS (TypeScript)
GenerateTests bool // Generate test setup
GenerateLinting bool // Generate linting setup
GenerateCI bool // Generate CI config
ErrorTaxonomy bool // Generate typed error classes
Interceptors bool // Generate interceptor support
Pagination bool // Generate pagination helpers
}
GeneratorConfig configures client generation.
func DefaultConfig ¶
func DefaultConfig() GeneratorConfig
DefaultConfig returns a default generator configuration.
func NewConfig ¶
func NewConfig(opts ...GeneratorOption) GeneratorConfig
NewConfig creates a new generator config with options.
func (*GeneratorConfig) Validate ¶
func (c *GeneratorConfig) Validate() error
Validate validates the configuration.
type GeneratorInfo ¶
GeneratorInfo provides information about a language generator.
type GeneratorOption ¶
type GeneratorOption func(*GeneratorConfig)
GeneratorOptions provides functional options for generator config.
func WithAPIName ¶
func WithAPIName(name string) GeneratorOption
WithAPIName sets the API client name.
func WithAuth ¶
func WithAuth(enabled bool) GeneratorOption
WithAuth enables/disables auth generation.
func WithFeatures ¶
func WithFeatures(features Features) GeneratorOption
WithFeatures sets the features.
func WithLanguage ¶
func WithLanguage(lang string) GeneratorOption
WithLanguage sets the target language.
func WithModule ¶
func WithModule(module string) GeneratorOption
WithModule sets the Go module path.
func WithOutputDir ¶
func WithOutputDir(dir string) GeneratorOption
WithOutputDir sets the output directory.
func WithPackageName ¶
func WithPackageName(name string) GeneratorOption
WithPackageName sets the package name.
func WithStreaming ¶
func WithStreaming(enabled bool) GeneratorOption
WithStreaming enables/disables streaming generation.
func WithVersion ¶
func WithVersion(version string) GeneratorOption
WithVersion sets the client version.
type HeartbeatConfig ¶
HeartbeatConfig configures heartbeat/ping behavior.
func DefaultHeartbeatConfig ¶
func DefaultHeartbeatConfig() HeartbeatConfig
DefaultHeartbeatConfig returns a sensible default heartbeat config.
type Introspector ¶
type Introspector struct {
// contains filtered or unexported fields
}
Introspector extracts API specification from a Forge Router.
func NewIntrospector ¶
func NewIntrospector(r router.Router) *Introspector
NewIntrospector creates a new introspector for a router.
func (*Introspector) Introspect ¶
func (i *Introspector) Introspect(ctx context.Context) (*APISpec, error)
Introspect extracts the complete API specification from the router.
type OAuthFlow ¶
type OAuthFlow struct {
AuthorizationURL string
TokenURL string
RefreshURL string
Scopes map[string]string
}
OAuthFlow defines a single OAuth 2.0 flow.
type OAuthFlows ¶
type OAuthFlows struct {
Implicit *OAuthFlow
Password *OAuthFlow
ClientCredentials *OAuthFlow
AuthorizationCode *OAuthFlow
}
OAuthFlows defines OAuth 2.0 flows.
type OutputManager ¶
type OutputManager struct{}
OutputManager handles writing generated client files to disk.
func NewOutputManager ¶
func NewOutputManager() *OutputManager
NewOutputManager creates a new output manager.
func (*OutputManager) GenerateREADME ¶
func (m *OutputManager) GenerateREADME(config GeneratorConfig, spec *APISpec, authDocs string) string
GenerateREADME generates a README for the client.
func (*OutputManager) WriteClient ¶
func (m *OutputManager) WriteClient(client *generators.GeneratedClient, outputDir string) error
WriteClient writes the generated client to disk.
type Parameter ¶
type Parameter struct {
Name string
In string // "path", "query", "header"
Description string
Required bool
Deprecated bool
Schema *Schema
Example any
}
Parameter represents a request parameter.
type ReconnectionConfig ¶
type ReconnectionConfig struct {
Strategy ReconnectionStrategy
InitialDelay time.Duration
MaxDelay time.Duration
MaxAttempts int
BackoffFactor float64 // For exponential strategy
JitterEnabled bool // Add random jitter to delays
}
ReconnectionConfig configures reconnection behavior.
func DefaultReconnectionConfig ¶
func DefaultReconnectionConfig() ReconnectionConfig
DefaultReconnectionConfig returns a sensible default reconnection config.
type ReconnectionStrategy ¶
type ReconnectionStrategy string
ReconnectionStrategy defines the strategy for reconnection.
const ( // ReconnectionStrategyExponential uses exponential backoff. ReconnectionStrategyExponential ReconnectionStrategy = "exponential" // ReconnectionStrategyLinear uses linear backoff. ReconnectionStrategyLinear ReconnectionStrategy = "linear" // ReconnectionStrategyFixed uses fixed delay. ReconnectionStrategyFixed ReconnectionStrategy = "fixed" )
type RequestBody ¶
type RequestBody struct {
Description string
Required bool
Content map[string]*MediaType // content-type -> media type
}
RequestBody represents a request body.
type Response ¶
type Response struct {
Description string
Content map[string]*MediaType // content-type -> media type
Headers map[string]*Parameter
}
Response represents an API response.
type SSEClientTemplate ¶
type SSEClientTemplate struct {
EndpointID string
Path string
EventSchemas map[string]*Schema
Features StreamingFeatures
ReconnectConfig ReconnectionConfig
}
SSEClientTemplate represents a template for SSE client generation.
type SSEEndpoint ¶
type SSEEndpoint struct {
ID string
Path string
Summary string
Description string
Tags []string
// Event schemas (event name -> schema)
EventSchemas map[string]*Schema
// Security
Security []SecurityRequirement
// Metadata
Metadata map[string]any
}
SSEEndpoint represents a Server-Sent Events endpoint.
func (*SSEEndpoint) GetType ¶
func (e *SSEEndpoint) GetType() EndpointType
GetEndpointType returns the type of endpoint.
type Schema ¶
type Schema struct {
Type string // "object", "array", "string", "number", "integer", "boolean", "null"
Format string // "date-time", "email", "uuid", etc.
Description string
Required []string // For object types
Properties map[string]*Schema
Items *Schema // For array types
Enum []any // For enum types
Default any
Example any
Nullable bool
ReadOnly bool
WriteOnly bool
MinLength *int
MaxLength *int
Minimum *float64
Maximum *float64
Pattern string
Ref string // Reference to another schema (e.g., "#/components/schemas/User")
// Polymorphism
OneOf []*Schema
AnyOf []*Schema
AllOf []*Schema
Discriminator *Discriminator
// Additional properties
AdditionalProperties any // bool or *Schema
}
Schema represents a data schema.
type SecurityRequirement ¶
SecurityRequirement represents a security requirement for an operation.
type SecurityScheme ¶
type SecurityScheme struct {
Type string // "apiKey", "http", "oauth2", "openIdConnect"
Name string // Scheme name
Description string
In string // "query", "header", "cookie" (for apiKey)
Scheme string // "bearer", "basic" (for http)
BearerFormat string // "JWT" (for http bearer)
Flows *OAuthFlows // For oauth2
OpenIDConnectURL string // For openIdConnect
CustomHeaders map[string]string // Custom headers
}
SecurityScheme represents an authentication/authorization scheme.
type Server ¶
type Server struct {
URL string
Description string
Variables map[string]ServerVariable
}
Server represents an API server.
type ServerVariable ¶
ServerVariable represents a variable in server URL.
type SpecParser ¶
type SpecParser struct{}
SpecParser parses OpenAPI and AsyncAPI specification files.
type StreamSchema ¶
type StreamSchema struct {
SendSchema *Schema // Client -> Server
ReceiveSchema *Schema // Server -> Client
}
StreamSchema represents a streaming data schema.
type StreamingCodeHelper ¶
type StreamingCodeHelper struct{}
StreamingCodeHelper provides helper methods for generating streaming code.
func NewStreamingCodeHelper ¶
func NewStreamingCodeHelper() *StreamingCodeHelper
NewStreamingCodeHelper creates a new streaming code helper.
func (*StreamingCodeHelper) GenerateHeartbeatDocs ¶
func (h *StreamingCodeHelper) GenerateHeartbeatDocs() string
GenerateHeartbeatDocs generates documentation for heartbeat.
func (*StreamingCodeHelper) GenerateReconnectionDocs ¶
func (h *StreamingCodeHelper) GenerateReconnectionDocs() string
GenerateReconnectionDocs generates documentation for reconnection.
func (*StreamingCodeHelper) GenerateStateManagementDocs ¶
func (h *StreamingCodeHelper) GenerateStateManagementDocs() string
GenerateStateManagementDocs generates documentation for state management.
type StreamingFeatures ¶
StreamingFeatures defines common streaming features and utilities.
type ValidationError ¶
ValidationError represents a validation error.
func (ValidationError) Error ¶
func (e ValidationError) Error() string
Error implements error interface.
type ValidationOptions ¶
type ValidationOptions struct {
RequireOperationIDs bool
RequireDescriptions bool
RequireExamples bool
RequireSecurity bool
}
ValidationOptions for API spec validation.
type WebSocketClientTemplate ¶
type WebSocketClientTemplate struct {
EndpointID string
Path string
SendSchema *Schema
ReceiveSchema *Schema
Features StreamingFeatures
ReconnectConfig ReconnectionConfig
HeartbeatConfig HeartbeatConfig
}
WebSocketClientTemplate represents a template for WebSocket client generation.
type WebSocketEndpoint ¶
type WebSocketEndpoint struct {
ID string
Path string
Summary string
Description string
Tags []string
// Message schemas
SendSchema *Schema // Client -> Server
ReceiveSchema *Schema // Server -> Client
// Security
Security []SecurityRequirement
// Metadata
Metadata map[string]any
}
WebSocketEndpoint represents a WebSocket endpoint.
func (*WebSocketEndpoint) GetType ¶
func (e *WebSocketEndpoint) GetType() EndpointType
GetEndpointType returns the type of endpoint.
type WebTransportEndpoint ¶
type WebTransportEndpoint struct {
ID string
Path string
Summary string
Description string
Tags []string
// Stream schemas
UniStreamSchema *StreamSchema // Unidirectional streams
BiStreamSchema *StreamSchema // Bidirectional streams
DatagramSchema *Schema // Unreliable datagrams
// Security
Security []SecurityRequirement
// Metadata
Metadata map[string]any
}
WebTransportEndpoint represents a WebTransport endpoint.
func (*WebTransportEndpoint) GetType ¶
func (e *WebTransportEndpoint) GetType() EndpointType
GetEndpointType returns the type of endpoint.