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
- func VisitDocumentOperations(root *yaml.Node, visit func(*yaml.Node))
- func VisitOperationIDs(root *yaml.Node, visit func(string))
- type ComponentGraph
- type ComponentID
- type FilterStats
- type MatchStrategy
- type OperationRefLookup
- type OperationRefTarget
- 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.
func VisitDocumentOperations ¶ added in v0.43.0
VisitDocumentOperations visits authored Operation Objects in a parsed OpenAPI 3 document.
func VisitOperationIDs ¶ added in v0.42.0
VisitOperationIDs visits IDs declared by Operation Objects in one parsed OpenAPI 3 document, including callbacks, webhooks and reusable Path Items. It does no I/O.
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 OperationRefLookup ¶ added in v0.43.0
OperationRefLookup indexes the mappings traversed by local Link operationRefs during one lint run.
func (OperationRefLookup) Target ¶ added in v0.43.0
func (lookup OperationRefLookup) Target(root *yaml.Node, ref string) OperationRefTarget
Target resolves a fragment-only JSON Pointer against the document that owns the link. Authors expect a pointer such as '#/paths/~1pets/get' to reach an operation in a referenced Path Item, so local references met on the way are followed and the strict pointer is recorded.
type OperationRefTarget ¶ added in v0.43.0
type OperationRefTarget struct {
// Node is the object at the pointer, or nil when the pointer is invalid or the target is not an object.
Node *yaml.Node
// Direct is an equivalent pointer that passes through no $ref. It is set only when the walk
// followed a local reference, which strict JSON Pointer evaluation does not do.
Direct string
// External is set when the walk reached a reference to another document. That target is not checked.
External bool
}
OperationRefTarget is the object a local Link operationRef leads to.
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.