utils

package
v0.20.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2025 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LocationRegex    = regexp.MustCompile(`((?:[a-zA-Z]:)?[^\s│]*?[/\\]?[^\s│/\\]+\.[a-zA-Z]+):(\d+):(\d+)`)
	JsonPathRegex    = regexp.MustCompile(`\$\.\S+`)
	CircularRefRegex = regexp.MustCompile(`\b[a-zA-Z0-9_-]+(?:\s*->\s*[a-zA-Z0-9_-]+)+\b`)
	PartRegex        = regexp.MustCompile(`([a-zA-Z0-9_-]+)|(\s*->\s*)`)
	BacktickRegex    = regexp.MustCompile("`([^`]+)`")
	SingleQuoteRegex = regexp.MustCompile(`'([^']+)'`)
	LogPrefixRegex   = regexp.MustCompile(`\[([^]]+)]`)
)

Functions

func BuildEndNode added in v0.9.0

func BuildEndNode(node *yaml.Node) *yaml.Node

BuildEndNode will return a new yaml.Node with the same line as the input node, but with a column that is the sum of the input node's column and the length of the input node's value.

func ConvertToMarshalable added in v0.17.10

func ConvertToMarshalable(data interface{}) interface{}

ConvertToMarshalable attempts to convert problematic structures to JSON-marshalable ones. This is a helper that can be used to fix issues, but for validation we just report them.

func CreateCustomHTTPClient added in v0.17.8

func CreateCustomHTTPClient(config HTTPClientConfig) (*http.Client, error)

CreateCustomHTTPClient creates an HTTP client with custom TLS configuration for certificate-based authentication and custom CA certificates.

func CreateRemoteURLHandler added in v0.17.8

func CreateRemoteURLHandler(client *http.Client) func(url string) (*http.Response, error)

CreateRemoteURLHandler creates a RemoteURLHandler function for use with libopenapi that uses the provided HTTP client for all remote requests.

func FilterIgnoredResults added in v0.17.11

func FilterIgnoredResults(results []model.RuleFunctionResult, ignored model.IgnoredItems) []model.RuleFunctionResult

FilterIgnoredResults does the filtering of ignored results on non-pointer result elements

func FilterIgnoredResultsPtr added in v0.17.11

func FilterIgnoredResultsPtr(results []*model.RuleFunctionResult, ignored model.IgnoredItems) []*model.RuleFunctionResult

FilterIgnoredResultsPtr filters the given results slice, taking out any (RuleID, Path) combos that were listed in the ignore file

func LocateComponentPaths added in v0.18.0

func LocateComponentPaths(
	context model.RuleFunctionContext,
	component v3.Foundational,
	keyNode *yaml.Node,
	valueNode *yaml.Node,
) (primaryPath string, allPaths []string)

LocateComponentPaths finds all paths where a component appears in the document. It uses DrDocument.LocateModelsByKeyAndValue to find all locations where the component is referenced, not just its definition location. This is a generic version that works with any component type that has GenerateJSONPath. Returns the primary path and all paths where the component appears.

func LocateSchemaPropertyPaths added in v0.17.10

func LocateSchemaPropertyPaths(
	context model.RuleFunctionContext,
	schema *v3.Schema,
	keyNode *yaml.Node,
	valueNode *yaml.Node,
) (primaryPath string, allPaths []string)

LocateSchemaPropertyPaths finds all paths where a schema property appears in the document. It uses DrDocument.LocateModelsByKeyAndValue to find all locations where the schema is referenced, not just its definition location. Returns the primary path and all paths where the schema appears.

func OpenURL added in v0.19.3

func OpenURL(url string) error

OpenURL opens the given URL in the system's default browser

func QuickCheckMarshalable added in v0.17.10

func QuickCheckMarshalable(data interface{}) bool

QuickCheckMarshalable does a quick check to see if data can be marshaled to JSON without doing a deep analysis. Returns true if marshalable, false otherwise.

func RenderMarkdownTable added in v0.16.15

func RenderMarkdownTable(headers []string, rows [][]string) string

RenderMarkdownTable builds a Markdown table from headers and rows.

func ShouldUseCustomHTTPClient added in v0.17.8

func ShouldUseCustomHTTPClient(config HTTPClientConfig) bool

ShouldUseCustomHTTPClient returns true if any TLS-related configuration is provided

func SuppliedOrDefault added in v0.7.0

func SuppliedOrDefault(supplied, original string) string

Types

type HTTPClientConfig added in v0.17.8

type HTTPClientConfig struct {
	CertFile string
	KeyFile  string
	CAFile   string
	Insecure bool
}

HTTPClientConfig holds configuration for creating a custom HTTP client

type LintFileRequest added in v0.9.0

type LintFileRequest struct {
	FileName                 string
	BaseFlag                 string
	MultiFile                bool
	Remote                   bool
	SkipCheckFlag            bool
	Silent                   bool
	DetailsFlag              bool
	TimeFlag                 bool
	NoMessageFlag            bool
	ExtensionRefs            bool
	AllResultsFlag           bool
	FailSeverityFlag         string
	CategoryFlag             string
	SnippetsFlag             bool
	ErrorsFlag               bool
	TotalFiles               int
	FileIndex                int
	TimeoutFlag              int
	LookupTimeoutFlag        int
	IgnoreArrayCircleRef     bool
	IgnorePolymorphCircleRef bool
	NoClip                   bool
	IgnoredResults           model.IgnoredItems
	DefaultRuleSets          rulesets.RuleSets
	SelectedRS               *rulesets.RuleSet
	Functions                map[string]model.RuleFunction
	Lock                     *sync.Mutex
	Logger                   *slog.Logger
	PipelineOutput           bool
	ShowRules                bool
	HTTPClientConfig         HTTPClientConfig
}

type MarshalingIssue added in v0.17.10

type MarshalingIssue struct {
	Line     int
	Column   int
	Path     string
	Reason   string
	KeyValue string // The actual key that's problematic
}

MarshalingIssue represents a location where JSON marshaling will fail

func CheckJSONMarshaling added in v0.17.10

func CheckJSONMarshaling(data interface{}, rootNode *yaml.Node) []MarshalingIssue

CheckJSONMarshaling attempts to marshal the data and returns any marshaling issues found. It only performs deep checking if the initial marshal fails.

func FindMarshalingIssuesInYAML added in v0.17.10

func FindMarshalingIssuesInYAML(rootNode *yaml.Node) []MarshalingIssue

FindMarshalingIssuesInYAML directly checks the YAML AST for marshaling issues without needing the unmarshaled data. This is useful when SpecJSON is nil.

Jump to

Keyboard shortcuts

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