core

package
v0.0.0-...-81fd40d Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capabilities

type Capabilities struct {
	SupportsClient     bool     // Can generate client code
	SupportsServer     bool     // Can generate server code
	SupportsValidation bool     // Can generate validators
	SupportsAsync      bool     // Supports async/await patterns
	SupportsStreaming  bool     // Supports streaming (SSE, Websockets)
	ClientFrameworks   []string // Supported client frameworks
	ServerFrameworks   []string // Supported server frameworks
}

Capabilities describes what a generator can produce

type Config

type Config struct {

	// Source
	SpecPath string

	// Output
	OutputDir string

	// Generator selection
	Generator string

	// What to generate
	Generate GenerateConfig

	// Generator-specific options
	Options map[string]interface{}

	// Template customization
	Templates TemplateConfig

	// Exclusions
	Exclude ExcludeConfig

	// Custom type mappings
	Types TypesConfig
}

type Contact

type Contact struct {
	Name  string
	Email string
	URL   string
}

type Discriminator

type Discriminator struct {
	PropertyName string
	Mapping      map[string]string
}

type Encoding

type Encoding struct {
	ContentType string // e.g., "application/json" or "image/png"

}

type Endpoint

type Endpoint struct {
	Path        string
	Method      string // GET, POST, PUT, DELETE, etc.
	OperationID string
	Summary     string
	Description string
	Tags        []string

	Parameters  []Parameter
	RequestBody *RequestBody
	Responses   []Response

	Security     []SecurityRequirement
	IsPublic     bool // true when security: [] is set explicitly (no auth required)
	IsDeprecated bool
}

type ErrorSeverity

type ErrorSeverity int
const (
	ErrorSeverityWarning ErrorSeverity = iota
	ErrorSeverityError
	ErrorSeverityFatal
)

type ExcludeConfig

type ExcludeConfig struct {
	Models []string // model names to skip (exact match)
	Tags   []string // operation tags to skip
}

ExcludeConfig specifies models and tags to skip during generation.

type Feature

type Feature string

Feature represents an OpeAPI feature

const (
	FeatureNullable      Feature = "nullable"
	FeatureDiscriminator Feature = "discriminator"
	FeatureOneOf         Feature = "oneOf"
	FeatureAllOf         Feature = "allOf"
	FeatureCallbacks     Feature = "callbacks"
	FeatureWebhooks      Feature = "webhooks"
	FeatureDeprecated    Feature = "deprecated"
	FeatureExamples      Feature = "examples"
	FeatureReadOnly      Feature = "readOnly"
	FeatureWriteOnly     Feature = "writeOnly"
)

type GenerateConfig

type GenerateConfig struct {
	Models, Client, Server, Validation bool
}

type GeneratedFile

type GeneratedFile struct {
	Path     string                 // Relative path from output dir
	Content  []byte                 // File content
	Metadata map[string]interface{} // Optional metadata
}

type GenerationError

type GenerationError struct {
	Severity ErrorSeverity
	Phase    string // "parsing", "validation", "generation"
	Location *Location
	Message  string
	Hint     string // Suggestion to fix
	Code     string // Error code (e.g., "E1001")
}

func (GenerationError) Error

func (e GenerationError) Error() string

type GenerationResult

type GenerationResult struct {
	Files    []GeneratedFile
	Warnings []GenerationError
}

type Generator

type Generator interface {

	// Metadata returs informatio about this generator
	Metadata() GeneratorMetadata

	// Validate checks if the spec and config are valid for this generator
	// Returns validation errors (does not stop on first error)
	Validate(spec *Spec, config *Config) []ValidationError

	// Generate produces code from the spec
	Generate(spec *Spec, config *Config) (*GenerationResult, error)

	// SupportedFeatures returns OpenAPI features this generator supports
	SupportedFeatures() []Feature
}

Generator is the interface that all language generators must implement

type GeneratorMetadata

type GeneratorMetadata struct {
	Name         string       // Unique identifier (e.g., "go-generator")
	Language     string       // Target language (e.g., "go", "typescript")
	Version      string       // Semantic version
	Description  string       // Human-readable description
	Author       string       // Author/maintainer
	Capabilities Capabilities // What this generator can produce
}

GeneratorMetadata describes the generator's capabilities

type Header struct {
	Description string
	Required    bool
	Schema      *Property
}

type License

type License struct {
	Name string
	URL  string
}

type Location

type Location struct {
	File   string // Spec file or template file
	Line   int
	Column int
	Path   string // JSON path (e.g., "#/paths/users/get")
}

type MediaType

type MediaType struct {
	Schema   *Property
	Example  interface{}
	Encoding map[string]Encoding // Mapping for multipart/form-data properties
}

type Model

type Model struct {
	Name        string
	Description string
	Type        string // "object", "array", "string", etc.
	Properties  []Property
	Required    []string
	Enum        []interface{}

	// For array type schemas
	IsArray bool      // true if this is an array schema
	Items   *Property // full items definition

	// For map type schemas (additionalProperties)
	IsMap           bool      // true if this is a map schema
	AdditionalProps *Property // the type of map values

	// Complex type handling
	AllOf []Model
	OneOf []Model
	AnyOf []Model

	// Metadata
	Discriminator *Discriminator
	IsDeprecated  bool
	Example       interface{}

	// Union type flags
	IsOneOf bool
	IsAnyOf bool

	// Source location
	SourcePath string // JSON Path in spec
}

type OAuthFlow

type OAuthFlow struct {
	AuthorizationURL string
	TokenURL         string
	RefreshURL       string
	Scopes           map[string]string
}

OAuthFlow represetns a single OAuth 2.0 flow

type OAuthFlows

type OAuthFlows struct {
	Implicit          *OAuthFlow
	Password          *OAuthFlow
	ClientCredentials *OAuthFlow
	AuthorizationCode *OAuthFlow
}

OAuthFlows represents OAuth 2.0 flow configurations

type Parameter

type Parameter struct {
	Name         string
	In           string // "path", "query", "header", "cookie"
	Description  string
	Required     bool
	Schema       *Property
	Example      interface{}
	IsDeprecated bool
}

type Property

type Property struct {
	Name        string
	Type        string
	Format      string
	Description string
	Required    bool
	Nullable    bool
	Enum        []interface{} // Enum values if this is an enum

	// Field metadata
	Default    interface{} // Default value
	ReadOnly   bool        // Read-only field
	WriteOnly  bool        // Write-only field
	Deprecated bool        // Deprecated field

	// Constraints
	Pattern     string
	MinLength   *int
	MaxLength   *int
	Minimum     *float64
	Maximum     *float64
	MinItems    *int
	MaxItems    *int
	UniqueItems bool
	MultipleOf  *float64

	// For nested types
	RefType string // Referenced type name (for $ref or nested objects)
	Items   *Property

	// For objects
	Properties []Property

	// Additional properties for maps
	AdditionalProperties *Property

	Example interface{}
}

func (Property) HasConstraints

func (p Property) HasConstraints() bool

HasConstraints returns true if the property has any spec-defined validation constraints.

type RefResolver

type RefResolver struct {
}

RefResolver handles $ref resolution in OpenAPI specs

type RequestBody

type RequestBody struct {
	Description string
	Required    bool
	Content     map[string]MediaType // media type -> schema
}

type Response

type Response struct {
	StatusCode  string // "200", "404", "default"
	Description string
	Headers     map[string]Header
	Content     map[string]MediaType
}

type SecurityRequirement

type SecurityRequirement struct {
	Name   string
	Scopes []string
}

type SecurityScheme

type SecurityScheme struct {
	Type             string // "apiKey", "http", "oauth2", "openIdConnect"
	Description      string
	Name             string // Scheme identifier (map key from spec, e.g. "bearerAuth")
	ParameterName    string // For apiKey: header/query/cookie parameter name (e.g. "X-API-Key")
	In               string // For apiKey: "header", "query", "cookie"
	Scheme           string // For http: "bearer", "basic", etc.
	BearerFormat     string // For http bearer
	Flows            *OAuthFlows
	OpenIDConnectURL string
}

SecuritySchema represents an authentication/authorization schema

func (SecurityScheme) IsAPIKey

func (s SecurityScheme) IsAPIKey() bool

IsAPIKey returns true if the scheme is an API key scheme.

func (SecurityScheme) IsBasicAuth

func (s SecurityScheme) IsBasicAuth() bool

IsBasicAuth returns true if the scheme is HTTP Basic authentication.

func (SecurityScheme) IsBearer

func (s SecurityScheme) IsBearer() bool

IsBearer returns true if the scheme is HTTP Bearer token.

func (SecurityScheme) IsOAuth2

func (s SecurityScheme) IsOAuth2() bool

IsOAuth2 returns true if the scheme is OAuth2.

type Spec

type Spec struct {
	Raw *openapi3.T

	Info        SpecInfo
	Models      []Model
	Endpoints   []Endpoint
	Tags        []Tag
	SecurityDef []SecurityScheme

	Version string // OpenAPI Version (e.g., "3.0.0")
	// contains filtered or unexported fields
}

Spec represents a processed OpenAPI specification

type SpecInfo

type SpecInfo struct {
	Title       string
	Description string
	Version     string
	Contact     *Contact
	License     *License
}

type Tag

type Tag struct {
	Name        string
	Description string
}

Tag represennts an API tag for grouping operations

type TemplateConfig

type TemplateConfig struct {
	CustomDir string            // Path to custom templates directory (supplements built-ins)
	Overrides map[string]string // template name → file path (replaces individual templates)
}

type TypeOverride

type TypeOverride struct {
	Format string // OpenAPI format (e.g. "email", "uuid", "date-time")
	Type   string // OpenAPI type (e.g. "integer") — matched when Format is ""
	Go     string // Target Go type (e.g. "uuid.UUID", "EmailAddress")
}

TypeOverride maps an OpenAPI format or type to a custom Go type. Format takes precedence over Type when both are set.

type TypesConfig

type TypesConfig struct {
	Overrides []TypeOverride
}

TypesConfig holds custom OpenAPI → Go type mappings.

type ValidationError

type ValidationError struct {
	GenerationError
}

Jump to

Keyboard shortcuts

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