typedef

package
v2.1.93 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildModel

func BuildModel(doc libopenapi.Document, simplify bool, optConfig *OptionalPropertyConfig) (*v3high.Document, error)

BuildModel builds the OpenAPI model from the document. If simplify is true, it also simplifies the model in-place (removes unions, limits optional properties). Returns the model which should be passed directly to CreateParseContextFromModel.

func CreateParseContext

func CreateParseContext(docContents []byte, cfg codegen.Configuration, specOptions *config.SpecOptions) (*codegen.ParseContext, []error)

func ExtractStaticResponses

func ExtractStaticResponses(specBytes []byte) (map[StaticResponseKey]string, error)

ExtractStaticResponses extracts all x-static-response values from an OpenAPI spec. Returns a map keyed by "METHOD /path statusCode" -> static response content.

Types

type LazyTypeDefinitionRegistry

type LazyTypeDefinitionRegistry struct {
	// contains filtered or unexported fields
}

LazyTypeDefinitionRegistry is a registry that parses operations on-demand. This significantly speeds up server startup for large specs by deferring the expensive schema parsing until an operation is actually accessed.

func NewLazyTypeDefinitionRegistry

func NewLazyTypeDefinitionRegistry(specBytes []byte, codegenCfg codegen.Configuration, specOptions *config.SpecOptions) (*LazyTypeDefinitionRegistry, error)

NewLazyTypeDefinitionRegistry creates a new lazy registry. It only extracts route paths/methods at startup - actual schema parsing is deferred.

func (*LazyTypeDefinitionRegistry) FindOperation

func (r *LazyTypeDefinitionRegistry) FindOperation(path, method string) *schema.Operation

FindOperation finds an operation by path and method. If not cached, it parses the operation on-demand and caches it. Method is case-insensitive (normalized to uppercase).

func (*LazyTypeDefinitionRegistry) GetResponseSchema

func (r *LazyTypeDefinitionRegistry) GetResponseSchema(path, method string) *schema.ResponseSchema

GetResponseSchema returns the success response schema for an operation.

func (*LazyTypeDefinitionRegistry) GetRouteInfo

func (r *LazyTypeDefinitionRegistry) GetRouteInfo() []RouteInfo

GetRouteInfo returns the list of all routes (for registering handlers).

func (*LazyTypeDefinitionRegistry) Operations

func (r *LazyTypeDefinitionRegistry) Operations() []*schema.Operation

Operations returns all cached operations. Note: For lazy registry, this only returns operations that have been accessed.

type OperationRegistry

type OperationRegistry interface {
	// FindOperation finds an operation by path and method.
	FindOperation(path, method string) *schema.Operation

	// Operations returns all operations (for lazy registry, only cached ones).
	Operations() []*schema.Operation

	// GetRouteInfo returns minimal route info for all operations.
	GetRouteInfo() []RouteInfo

	// GetResponseSchema returns the success response schema for an operation.
	// Returns nil if the operation is not found or has no success response.
	GetResponseSchema(path, method string) *schema.ResponseSchema
}

OperationRegistry is the interface for accessing parsed operations. Both TypeDefinitionRegistry (eager) and LazyTypeDefinitionRegistry (lazy) implement this.

func NewRegistryFromSpec

func NewRegistryFromSpec(specBytes []byte, codegenCfg codegen.Configuration, specOptions *config.SpecOptions) (OperationRegistry, error)

NewRegistryFromSpec creates an OperationRegistry from raw OpenAPI spec bytes. This is a convenience function that handles parsing and registry creation. If specOptions.LazyLoad is true, operations are parsed on-demand for faster startup.

type OptionalPropertyConfig

type OptionalPropertyConfig struct {
	// Min: minimum number of optional properties to keep
	Min int

	// Max: maximum number of optional properties to keep
	// If Min == Max, keeps exactly that many
	Max int

	// Seed for random number generation (0 = use current time)
	Seed int64
}

OptionalPropertyConfig controls how optional properties are removed

type RouteInfo

type RouteInfo struct {
	ID     string
	Method string
	Path   string
}

RouteInfo holds minimal route information extracted at startup.

type StaticResponseKey

type StaticResponseKey string

StaticResponseKey is a unique key for looking up static responses. Format: "METHOD /path 200" (e.g., "GET /users 200")

func NewStaticResponseKey

func NewStaticResponseKey(method, path string, statusCode int) StaticResponseKey

NewStaticResponseKey creates a key for looking up static responses.

type StaticRoute

type StaticRoute struct {
	Method      string
	Path        string
	ContentType string
	Content     string
}

StaticRoute represents a static route with its content.

type TypeDefinitionRegistry

type TypeDefinitionRegistry struct {
	// contains filtered or unexported fields
}

TypeDefinitionRegistry is a struct that holds all type definitions and operations.

func NewRegistryFromStaticRoutes

func NewRegistryFromStaticRoutes(routes []StaticRoute) (*TypeDefinitionRegistry, error)

NewRegistryFromStaticRoutes creates a TypeDefinitionRegistry from static routes. It builds Operation objects with schemas inferred from the static content.

func NewTypeDefinitionRegistry

func NewTypeDefinitionRegistry(parseCtx *codegen.ParseContext, maxRecursionDepth int, specBytes []byte) *TypeDefinitionRegistry

NewTypeDefinitionRegistry creates a new TypeDefinitionRegistry instance. It extracts x-static-response extensions from the spec if specBytes is provided.

func (*TypeDefinitionRegistry) FindOperation

func (td *TypeDefinitionRegistry) FindOperation(path, method string) *schema.Operation

FindOperation finds an operation by path and method. Method is case-insensitive (normalized to uppercase).

func (*TypeDefinitionRegistry) GetResponseSchema

func (td *TypeDefinitionRegistry) GetResponseSchema(path, method string) *schema.ResponseSchema

GetResponseSchema returns the success response schema for an operation.

func (*TypeDefinitionRegistry) GetRouteInfo

func (td *TypeDefinitionRegistry) GetRouteInfo() []RouteInfo

GetRouteInfo returns minimal route info for all operations. This implements the OperationRegistry interface.

func (*TypeDefinitionRegistry) GetTypeDefinitionLookup

func (td *TypeDefinitionRegistry) GetTypeDefinitionLookup() map[string]*codegen.TypeDefinition

GetTypeDefinitionLookup returns a map of all type definitions.

func (*TypeDefinitionRegistry) Operations

func (td *TypeDefinitionRegistry) Operations() []*schema.Operation

Jump to

Keyboard shortcuts

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