openax

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapError added in v0.1.0

func WrapError(err error, operation string, location *SourceLocation) error

WrapError wraps an error with additional context and location information.

Types

type Client

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

Client provides the main interface for OpenAPI operations.

func New

func New() *Client

New creates a new OpenAx client with default options.

func NewWithOptions

func NewWithOptions(opts LoadOptions) *Client

NewWithOptions creates a new OpenAx client with custom options.

func (*Client) Filter

func (c *Client) Filter(doc *openapi3.T, opts FilterOptions) (*openapi3.T, error)

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

func (c *Client) LoadAndFilter(source string, opts FilterOptions) (*openapi3.T, error)

LoadAndFilter is a convenience method that loads and filters a specification in one call.

func (*Client) LoadFromData

func (c *Client) LoadFromData(data []byte) (*openapi3.T, error)

LoadFromData loads an OpenAPI specification from raw data.

func (*Client) LoadFromFile

func (c *Client) LoadFromFile(filePath string) (*openapi3.T, error)

LoadFromFile loads an OpenAPI specification from a local file.

func (*Client) LoadFromURL

func (c *Client) LoadFromURL(urlStr string) (*openapi3.T, error)

LoadFromURL loads an OpenAPI specification from a URL.

func (*Client) Validate

func (c *Client) Validate(doc *openapi3.T) error

Validate validates an OpenAPI specification.

func (*Client) ValidateOnly

func (c *Client) ValidateOnly(source string) error

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.

Jump to

Keyboard shortcuts

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