Documentation
¶
Overview ¶
Package transform provides in-place, document-aware OpenAPI transformations.
The package operates directly on YAML node trees so retained ordering, scalar style, comments, and extension fields are preserved.
Index ¶
- func HasReachableOperations(root *yaml.Node, specVersion string) bool
- func Transform(root *yaml.Node, specVersion string, options Options) (FilterStats, PruneStats, error)
- func ValidateBundled(root *yaml.Node) error
- func ValidateTagFilterOptions(options TagFilterOptions) error
- type ComponentGraph
- type ComponentID
- type FilterStats
- type MatchStrategy
- type Options
- type PruneStats
- type TagFilterOptions
- type Warning
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasReachableOperations ¶
HasReachableOperations reports whether at least one operation is reachable from the document's Paths or Webhooks Objects. Unreferenced reusable Path Items and Callbacks are not publication roots.
func Transform ¶
func Transform(root *yaml.Node, specVersion string, options Options) (FilterStats, PruneStats, error)
Transform filters operations and prunes unused components with one YAML preparation and bundled-reference validation pass. Standalone filter and prune entry points use this same path.
func ValidateBundled ¶
ValidateBundled rejects document references whose URI portion is external. Runtime URLs such as Example Object externalValue values are ignored.
func ValidateTagFilterOptions ¶
func ValidateTagFilterOptions(options TagFilterOptions) error
ValidateTagFilterOptions checks the tag match strategy and rejects blank values.
Types ¶
type ComponentGraph ¶
type ComponentGraph struct {
// contains filtered or unexported fields
}
ComponentGraph is a read-only reachability graph for reusable components.
func BuildComponentGraph ¶
func BuildComponentGraph(root *yaml.Node, specVersion string) (*ComponentGraph, error)
BuildComponentGraph validates local component references and builds a graph whose roots are references made by the retained, non-component document.
func (*ComponentGraph) Unreachable ¶
func (g *ComponentGraph) Unreachable() []ComponentID
Unreachable returns registered components not reachable from document roots.
type ComponentID ¶
ComponentID uniquely identifies a reusable OpenAPI component.
type FilterStats ¶
type FilterStats struct {
OperationsSeen int
OperationsKept int
OperationsRemoved int
PathItemsRemoved int
WebhooksRemoved int
CallbackItemsRemoved int
Warnings []Warning
}
FilterStats summarizes operation filtering.
func FilterOperationsByTags ¶
func FilterOperationsByTags(root *yaml.Node, specVersion string, options TagFilterOptions) (FilterStats, error)
FilterOperationsByTags applies the configured tag and operation-ID filters. Empty filter lists are a no-op. Exclusions take precedence over inclusions.
type MatchStrategy ¶
type MatchStrategy string
MatchStrategy controls how operation tags match each include/exclude list.
const ( // MatchAny keeps an operation containing at least one included tag. MatchAny MatchStrategy = "any" // MatchAll keeps an operation containing every included tag. MatchAll MatchStrategy = "all" )
type Options ¶
type Options struct {
TagFilter TagFilterOptions
PruneUnused bool
// PruneUnusedTags removes tag definitions unused by operations or documentation.
PruneUnusedTags bool
}
Options selects publication transforms. Filtering runs before pruning so only components reachable from retained operations remain.
type PruneStats ¶
type PruneStats struct {
// TagsRemoved counts top-level tag definitions unused by retained operations.
TagsRemoved int
ComponentsSeen int
ComponentsKept int
ComponentsRemoved int
RemovedBySection map[string]int
// contains filtered or unexported fields
}
PruneStats summarizes component reachability and unused-tag pruning.
func PruneUnusedComponents ¶
func PruneUnusedComponents(root *yaml.Node, specVersion string) (PruneStats, error)
PruneUnusedComponents removes reusable components unreachable from retained document content. Top-level Tag Objects are not pruned.
type TagFilterOptions ¶
type TagFilterOptions struct {
IncludeTags []string
MatchStrategy MatchStrategy
// ExcludeTags removes operations matching these tags with MatchStrategy.
ExcludeTags []string
// IncludeOperationIDs keeps operations with any of these exact IDs.
IncludeOperationIDs []string
// ExcludeOperationIDs removes operations with any of these exact IDs.
ExcludeOperationIDs []string
}
TagFilterOptions configures operation filtering. Active inclusion filters must all match. Exclusions take precedence. Names are case-sensitive.
func (TagFilterOptions) Enabled ¶ added in v0.34.0
func (o TagFilterOptions) Enabled() bool
Enabled reports whether at least one operation filter is configured.
type Warning ¶
Warning describes a non-fatal publication problem found by a transform.
func RetainWarningsForPrunedDocument ¶
func RetainWarningsForPrunedDocument(warnings []Warning, prune PruneStats) []Warning
RetainWarningsForPrunedDocument removes warnings owned by components that were deleted by the supplied prune operation.