commands

package
v1.51.3 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package commands provides CLI command handlers for oastools.

Index

Constants

View Source
const (
	FormatText = "text"
	FormatJSON = "json"
	FormatYAML = "yaml"
)

Output format constants

View Source
const StdinFilePath = "-"

StdinFilePath is the special file path used to indicate reading from stdin.

Variables

This section is empty.

Functions

func FormatExtensions added in v1.50.0

func FormatExtensions(extra map[string]any) string

FormatExtensions formats a map of extensions as a comma-separated string for summary output. Keys are sorted for deterministic output.

func FormatSpecPath added in v1.30.1

func FormatSpecPath(specPath string) string

FormatSpecPath returns a display-friendly path for the specification. Returns "<stdin>" if the path is StdinFilePath, otherwise returns the path as-is.

func HandleConvert

func HandleConvert(args []string) error

HandleConvert executes the convert command

func HandleDiff

func HandleDiff(args []string) error

HandleDiff executes the diff command

func HandleFix

func HandleFix(args []string) error

HandleFix executes the fix command

func HandleGenerate

func HandleGenerate(args []string) error

HandleGenerate executes the generate command

func HandleJoin

func HandleJoin(args []string) error

HandleJoin executes the join command

func HandleOverlay added in v1.24.0

func HandleOverlay(args []string) error

HandleOverlay executes the overlay command

func HandleParse

func HandleParse(args []string) error

HandleParse executes the parse command

func HandleValidate

func HandleValidate(args []string) error

HandleValidate executes the validate command

func HandleWalk added in v1.50.0

func HandleWalk(args []string) error

HandleWalk routes the walk command to the appropriate subcommand handler.

func MapPrimaryOperationPolicy added in v1.39.1

func MapPrimaryOperationPolicy(policy string) joiner.PrimaryOperationPolicy

MapPrimaryOperationPolicy maps a string policy to the joiner enum.

func MarshalDocument

func MarshalDocument(doc any, format parser.SourceFormat) ([]byte, error)

MarshalDocument marshals a document to bytes in the specified format

func OutputSpecHeader added in v1.35.0

func OutputSpecHeader(specPath, version string)

OutputSpecHeader outputs the common specification header to stderr. This includes oastools version, specification path, and OAS version.

func OutputSpecStats added in v1.35.0

func OutputSpecStats(sourceSize int64, stats parser.DocumentStats, loadTime any)

OutputSpecStats outputs the common specification statistics to stderr. This includes source size, path count, operation count, schema count, and load time.

func OutputStructured

func OutputStructured(data any, format string) error

OutputStructured outputs data in the specified format (json or yaml) to stdout. Returns an error if marshaling fails.

func RenderDetail added in v1.50.0

func RenderDetail(w io.Writer, node any, format string) error

RenderDetail renders a single node in the specified format (JSON, YAML, or text).

func RenderSummaryStructured added in v1.50.1

func RenderSummaryStructured(w io.Writer, headers []string, rows [][]string, format string) error

RenderSummaryStructured renders summary table data as structured output (JSON or YAML). It converts header+row pairs into []map[string]string with lowercase keys.

func RenderSummaryTable added in v1.50.0

func RenderSummaryTable(w io.Writer, headers []string, rows [][]string, quiet bool)

RenderSummaryTable renders a table of results. In quiet mode, headers are omitted and rows are tab-separated for piping. In normal mode, a fixed-width table with headers is rendered.

func ValidateCollisionStrategy

func ValidateCollisionStrategy(strategyName, value string) error

ValidateCollisionStrategy validates a collision strategy name and returns an error if invalid. The strategyName parameter is used in the error message (e.g., "path-strategy").

func ValidateEquivalenceMode added in v1.23.0

func ValidateEquivalenceMode(value string) error

ValidateEquivalenceMode validates an equivalence mode and returns an error if invalid.

func ValidateOutputFormat

func ValidateOutputFormat(format string) error

ValidateOutputFormat validates an output format and returns an error if invalid.

func ValidateOutputPath

func ValidateOutputPath(outputPath string, inputPaths []string) error

ValidateOutputPath checks if the output path is safe to write to

func ValidatePrimaryOperationPolicy added in v1.39.1

func ValidatePrimaryOperationPolicy(policy string) error

ValidatePrimaryOperationPolicy validates the primary operation policy flag value.

func Writef added in v1.34.0

func Writef(w io.Writer, format string, args ...any)

Writef writes formatted output to the writer. If the write fails, it logs to stderr (useful for debugging).

Types

type ConvertFlags

type ConvertFlags struct {
	Target     string
	Output     string
	Strict     bool
	NoWarnings bool
	Quiet      bool
	SourceMap  bool
}

ConvertFlags contains flags for the convert command

func SetupConvertFlags

func SetupConvertFlags() (*flag.FlagSet, *ConvertFlags)

SetupConvertFlags creates and configures a FlagSet for the convert command. Returns the FlagSet and a ConvertFlags struct with bound flag variables.

type DiffFlags

type DiffFlags struct {
	Breaking  bool
	NoInfo    bool
	Format    string
	SourceMap bool
}

DiffFlags contains flags for the diff command

func SetupDiffFlags

func SetupDiffFlags() (*flag.FlagSet, *DiffFlags)

SetupDiffFlags creates and configures a FlagSet for the diff command. Returns the FlagSet and a DiffFlags struct with bound flag variables.

type ExtensionExpr added in v1.50.0

type ExtensionExpr struct {
	Key     string  // e.g., "x-audited-by"
	Value   *string // nil = existence check only
	Negated bool    // ! prefix or != operator
}

ExtensionExpr is a single extension filter expression.

type ExtensionFilter added in v1.50.0

type ExtensionFilter struct {
	Groups [][]ExtensionExpr
}

ExtensionFilter represents a parsed --extension filter. Groups are OR'd together; expressions within a group are AND'd.

func ParseExtensionFilter added in v1.50.0

func ParseExtensionFilter(input string) (ExtensionFilter, error)

ParseExtensionFilter parses the --extension flag value. Grammar: FILTER = EXPR ( ("," | "+") EXPR )* , = OR (separates groups), + = AND (within a group)

func (ExtensionFilter) Match added in v1.50.0

func (f ExtensionFilter) Match(extensions map[string]any) bool

Match evaluates the filter against a node's extensions. Returns true if the filter matches.

type FixFlags

type FixFlags struct {
	Output    string
	Infer     bool
	Quiet     bool
	SourceMap bool

	// Schema name fixing flags
	FixSchemaNames        bool
	GenericNaming         string
	GenericSeparator      string
	GenericParamSeparator string
	PreserveCasing        bool

	// Pruning flags
	PruneSchemas bool
	PrunePaths   bool
	PruneAll     bool

	// Duplicate operationId fixing flags
	FixDuplicateOperationIds bool
	OperationIdTemplate      string
	OperationIdPathSep       string
	OperationIdTagSep        string

	// Stub missing refs flags
	StubMissingRefs  bool
	StubResponseDesc string

	// Dry run flag
	DryRun bool
}

FixFlags contains flags for the fix command

func SetupFixFlags

func SetupFixFlags() (*flag.FlagSet, *FixFlags)

SetupFixFlags creates and configures a FlagSet for the fix command. Returns the FlagSet and a FixFlags struct with bound flag variables.

type GenerateFlags

type GenerateFlags struct {
	Output       string
	PackageName  string
	Client       bool
	Server       bool
	Types        bool
	NoPointers   bool
	NoValidation bool
	Strict       bool
	NoWarnings   bool
	SourceMap    bool

	// Security generation options
	NoSecurity      bool
	OAuth2Flows     bool
	CredentialMgmt  bool
	SecurityEnforce bool
	OIDCDiscovery   bool
	NoReadme        bool

	// File splitting options
	MaxLinesPerFile int
	MaxTypesPerFile int
	MaxOpsPerFile   int
	SplitByTag      bool
	NoSplitByTag    bool
	SplitByPath     bool
	NoSplitByPath   bool

	// Server generation options
	ServerRouter     string
	ServerMiddleware bool
	ServerBinder     bool
	ServerResponses  bool
	ServerStubs      bool
	ServerEmbedSpec  bool
	ServerAll        bool
}

GenerateFlags contains flags for the generate command

func SetupGenerateFlags

func SetupGenerateFlags() (*flag.FlagSet, *GenerateFlags)

SetupGenerateFlags creates and configures a FlagSet for the generate command. Returns the FlagSet and a GenerateFlags struct with bound flag variables.

type JoinFlags

type JoinFlags struct {
	Output            string
	PathStrategy      string
	SchemaStrategy    string
	ComponentStrategy string
	NoMergeArrays     bool
	NoDedupTags       bool
	Quiet             bool
	SourceMap         bool
	// Advanced collision strategies
	RenameTemplate  string
	EquivalenceMode string
	CollisionReport bool
	SemanticDedup   bool
	// Namespace prefix configuration
	NamespacePrefix namespacePrefixFlag
	AlwaysPrefix    bool
	// Operation context configuration
	OperationContext       bool
	PrimaryOperationPolicy string
	// Overlay configuration
	PreOverlays stringSliceFlag
	PostOverlay string
}

JoinFlags contains flags for the join command

func SetupJoinFlags

func SetupJoinFlags() (*flag.FlagSet, *JoinFlags)

SetupJoinFlags creates and configures a FlagSet for the join command. Returns the FlagSet and a JoinFlags struct with bound flag variables.

type OverlayApplyFlags added in v1.24.0

type OverlayApplyFlags struct {
	Spec   string
	Output string
	Strict bool
	Quiet  bool
	DryRun bool
}

OverlayApplyFlags contains flags for the overlay apply command

func SetupOverlayApplyFlags added in v1.24.0

func SetupOverlayApplyFlags() (*flag.FlagSet, *OverlayApplyFlags)

SetupOverlayApplyFlags creates and configures a FlagSet for the overlay apply command. Returns the FlagSet and an OverlayApplyFlags struct with bound flag variables.

type OverlayValidateFlags added in v1.24.0

type OverlayValidateFlags struct {
	Quiet bool
}

OverlayValidateFlags contains flags for the overlay validate command

func SetupOverlayValidateFlags added in v1.24.0

func SetupOverlayValidateFlags() (*flag.FlagSet, *OverlayValidateFlags)

SetupOverlayValidateFlags creates and configures a FlagSet for the overlay validate command. Returns the FlagSet and an OverlayValidateFlags struct with bound flag variables.

type ParseFlags

type ParseFlags struct {
	ResolveRefs       bool
	ResolveHTTPRefs   bool
	Insecure          bool
	ValidateStructure bool
	Quiet             bool
}

ParseFlags contains flags for the parse command

func SetupParseFlags

func SetupParseFlags() (*flag.FlagSet, *ParseFlags)

SetupParseFlags creates and configures a FlagSet for the parse command. Returns the FlagSet and a ParseFlags struct with bound flag variables.

type ValidateFlags

type ValidateFlags struct {
	Strict            bool
	ValidateStructure bool
	NoWarnings        bool
	Quiet             bool
	Format            string
	SourceMap         bool
	IncludeDocument   bool
}

ValidateFlags contains flags for the validate command

func SetupValidateFlags

func SetupValidateFlags() (*flag.FlagSet, *ValidateFlags)

SetupValidateFlags creates and configures a FlagSet for the validate command. Returns the FlagSet and a ValidateFlags struct with bound flag variables.

type WalkFlags added in v1.50.0

type WalkFlags struct {
	Format      string // Output format: text, json, yaml.
	Quiet       bool   // Suppress headers and decoration for piping.
	Detail      bool   // Show full node instead of summary table.
	Extension   string // Extension filter expression (e.g., "x-internal=true").
	ResolveRefs bool   // Resolve $ref pointers before output.
}

WalkFlags contains common flags shared by all walk subcommands.

Jump to

Keyboard shortcuts

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