Documentation
¶
Overview ¶
Package openax provides OpenAPI specification filtering and validation capabilities. It can be used both as a library and as a CLI tool to filter OpenAPI specs by paths, operations, and tags while resolving component dependencies.
Index ¶
- func WrapError(err error, operation string, location *SourceLocation) error
- type Client
- func (c *Client) Filter(doc *openapi3.T, opts FilterOptions) (*openapi3.T, error)
- func (c *Client) LoadAndFilter(source string, opts FilterOptions) (*openapi3.T, error)
- func (c *Client) LoadFromData(data []byte) (*openapi3.T, error)
- func (c *Client) LoadFromFile(filePath string) (*openapi3.T, error)
- func (c *Client) LoadFromURL(urlStr string) (*openapi3.T, error)
- func (c *Client) Validate(doc *openapi3.T) error
- func (c *Client) ValidateOnly(source string) error
- type ComponentNotFoundError
- type ComponentUsage
- type FilterError
- type FilterOptions
- type InvalidReferenceError
- type LoadOptions
- type ProcessedRefs
- type SourceLocation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides the main interface for OpenAPI operations.
func NewWithOptions ¶
func NewWithOptions(opts LoadOptions) *Client
NewWithOptions creates a new OpenAx client with custom options.
func (*Client) Filter ¶
Filter applies filtering to an OpenAPI specification based on the provided options. It returns a new specification containing only the requested paths, operations, and tags, along with all referenced components (schemas, parameters, request bodies, responses).
func (*Client) LoadAndFilter ¶
LoadAndFilter is a convenience method that loads and filters a specification in one call.
func (*Client) LoadFromData ¶
LoadFromData loads an OpenAPI specification from raw data.
func (*Client) LoadFromFile ¶
LoadFromFile loads an OpenAPI specification from a local file.
func (*Client) LoadFromURL ¶
LoadFromURL loads an OpenAPI specification from a URL.
func (*Client) ValidateOnly ¶
ValidateOnly loads and validates a specification without filtering.
type ComponentNotFoundError ¶ added in v0.1.0
type ComponentNotFoundError struct {
Name string
Type string
Context string
Location *SourceLocation // Location where the reference was found
Cause error // Underlying cause of the error
}
ComponentNotFoundError indicates that a referenced component was not found.
func (ComponentNotFoundError) Error ¶ added in v0.1.0
func (e ComponentNotFoundError) Error() string
func (ComponentNotFoundError) Unwrap ¶ added in v0.1.0
func (e ComponentNotFoundError) Unwrap() error
Unwrap returns the underlying cause of the error.
type ComponentUsage ¶ added in v0.1.0
type ComponentUsage struct {
Schemas map[string]bool
Parameters map[string]bool
RequestBodies map[string]bool
Responses map[string]bool
}
ComponentUsage tracks which components are used
type FilterError ¶ added in v0.1.0
type FilterError struct {
Operation string // The operation being performed (e.g., "filtering paths", "resolving schema")
Location *SourceLocation // Location in the OpenAPI specification
Cause error // Underlying cause of the error
}
FilterError represents an error that occurred during the filtering process.
func (FilterError) Error ¶ added in v0.1.0
func (e FilterError) Error() string
func (FilterError) Unwrap ¶ added in v0.1.0
func (e FilterError) Unwrap() error
Unwrap returns the underlying cause of the error.
type FilterOptions ¶
type FilterOptions struct {
// Paths specifies which paths to include (e.g., "/users", "/orders")
// If empty, all paths are considered
Paths []string
// Operations specifies which HTTP operations to include (e.g., "get", "post")
// Can also include operation IDs
// If empty, all operations are considered
Operations []string
// Tags specifies which tags to include
// If empty, all tags are considered
Tags []string
// PruneComponents removes unused components from the filtered specification
// This helps reduce specification size and improves readability
PruneComponents bool
}
FilterOptions defines the filtering criteria for OpenAPI specifications.
type InvalidReferenceError ¶ added in v0.1.0
type InvalidReferenceError struct {
Ref string
Reason string
Location *SourceLocation // Location where the invalid reference was found
Cause error // Underlying cause of the error
}
InvalidReferenceError indicates that a reference string is invalid.
func (InvalidReferenceError) Error ¶ added in v0.1.0
func (e InvalidReferenceError) Error() string
func (InvalidReferenceError) Unwrap ¶ added in v0.1.0
func (e InvalidReferenceError) Unwrap() error
Unwrap returns the underlying cause of the error.
type LoadOptions ¶
type LoadOptions struct {
// AllowExternalRefs enables loading of external references
AllowExternalRefs bool
// Context for the loading operation
Context context.Context
}
LoadOptions defines options for loading OpenAPI specifications.
type ProcessedRefs ¶ added in v0.1.0
type ProcessedRefs struct {
Schemas map[string]bool
RequestBodies map[string]bool
Parameters map[string]bool
Responses map[string]bool
}
ProcessedRefs holds all processed reference maps
type SourceLocation ¶ added in v0.1.0
type SourceLocation struct {
FilePath string // Path to the source file
Line int // Line number (0-based)
Column int // Column number (0-based)
Path string // JSONPath or YAML path within the document (e.g., "paths./pet.get")
}
SourceLocation represents a location in a source file or OpenAPI specification.
func (SourceLocation) String ¶ added in v0.1.0
func (sl SourceLocation) String() string
String returns a human-readable representation of the source location.