Documentation
¶
Index ¶
- Variables
- func ExtractOpenAPIMetadata(body []byte, result *models.ValidationResult)
- func GetCategories() ([]string, error)
- func GetCommonDomains() []string
- func LooksOpenAPI(body []byte) bool
- func NewValidatorFactory(proxy string, timeout int) (*ValidatorFactory, []ProviderConfig, *client.ProxyRotator, error)
- func NewValidatorFactoryWithOptions(proxy string, timeout int, opts FactoryOptions) (*ValidatorFactory, []ProviderConfig, *client.ProxyRotator, error)
- type DetectionConfig
- type DetectionResult
- type Detector
- type DetectorIndex
- type EndpointConfig
- type ErrorCheck
- type FactoryOptions
- type FailureWhen
- type GenericValidator
- func (v *GenericValidator) Config() ProviderConfig
- func (v *GenericValidator) FetchMetadata(ctx context.Context, apiKey string, result *models.ValidationResult)
- func (v *GenericValidator) KeyPatterns() []string
- func (v *GenericValidator) Name() string
- func (v *GenericValidator) SetCache(cache client.ResultCache)
- func (v *GenericValidator) SetCanaryCheck(check bool)
- func (v *GenericValidator) SetSkipMetadata(skip bool)
- func (v *GenericValidator) Validate(ctx context.Context, apiKey string) (*models.ValidationResult, error)
- type LintIssue
- type LintSeverity
- type MetadataConfig
- type MetadataFromValidation
- type PatternEntry
- type PrefixEntry
- type PrefixIndex
- type PrefixTrie
- type ProviderConfig
- type ProviderInfo
- type ResponseMatch
- type RetryPolicy
- type TrieNode
- type ValidationConfig
- type Validator
- type ValidatorFactory
- func (f *ValidatorFactory) Cache() client.ResultCache
- func (f *ValidatorFactory) GetValidator(name string) (Validator, bool)
- func (f *ValidatorFactory) RegisterConfig(cfg ProviderConfig)
- func (f *ValidatorFactory) SharedClient() *http.Client
- func (f *ValidatorFactory) SharedLimiter() *client.RateLimiterManager
Constants ¶
This section is empty.
Variables ¶
var (
CustomProvidersDir string
)
Functions ¶
func ExtractOpenAPIMetadata ¶ added in v1.2.1
func ExtractOpenAPIMetadata(body []byte, result *models.ValidationResult)
ExtractOpenAPIMetadata walks an OpenAPI/Swagger document and stamps the results on the ValidationResult. Caller should check LooksOpenAPI first.
Adds (when present):
extra.openapi_paths -> number of path entries extra.openapi_schemas -> number of schemas under components / definitions extra.openapi_version -> "3.x.x" or "2.x" extra.openapi_title -> info.title
func GetCategories ¶ added in v1.0.3
func GetCommonDomains ¶ added in v1.0.8
func GetCommonDomains() []string
func LooksOpenAPI ¶ added in v1.2.1
LooksOpenAPI returns true when the body has the basic shape of an OpenAPI or Swagger document. We only sniff well-known top-level keys to avoid false positives on regular API responses.
func NewValidatorFactory ¶ added in v1.0.8
func NewValidatorFactory(proxy string, timeout int) (*ValidatorFactory, []ProviderConfig, *client.ProxyRotator, error)
func NewValidatorFactoryWithOptions ¶ added in v1.2.0
func NewValidatorFactoryWithOptions(proxy string, timeout int, opts FactoryOptions) (*ValidatorFactory, []ProviderConfig, *client.ProxyRotator, error)
NewValidatorFactoryWithOptions is the configurable constructor. opts.PersistentCachePath enables a cross-run positive cache; opts.DisableCache forces every request through the network regardless of either cache layer.
Types ¶
type DetectionConfig ¶ added in v1.2.1
type DetectionConfig struct {
// MinScore is the minimum total detection score for this provider to be
// considered a match. The default detector scoring produces scores well
// over 100 for a confident match; values in the 50-150 range are typical
// tuning points.
MinScore int `yaml:"min_score,omitempty"`
}
DetectionConfig carries per-provider detection tuning.
type DetectionResult ¶ added in v1.0.4
type DetectionResult struct {
Provider string
Suggestions []string
Message string
Entropy float64
// Score is the detection confidence score for the chosen provider. Higher
// is more confident; providers without an entry get a default of 0.
Score int
}
func DetectProviderWithSuggestion ¶ added in v1.0.4
func DetectProviderWithSuggestion(key string, idx *DetectorIndex, manualCategory string) DetectionResult
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
func NewDetector ¶
func NewDetector() *Detector
func NewDetectorFromConfigs ¶
func NewDetectorFromConfigs(configs []ProviderConfig) *Detector
func (*Detector) DetectProvider ¶
func (*Detector) DetectProviderWithSuggestion ¶ added in v1.0.4
func (d *Detector) DetectProviderWithSuggestion(apiKey string, manualCategory string) DetectionResult
type DetectorIndex ¶ added in v1.0.7
type DetectorIndex struct {
// contains filtered or unexported fields
}
func BuildDetectionIndex ¶
func BuildDetectionIndex(configs []ProviderConfig) *DetectorIndex
type EndpointConfig ¶ added in v1.0.9
type ErrorCheck ¶ added in v1.0.9
type ErrorCheck struct {
JSONPath string `yaml:"json_path,omitempty"`
}
type FactoryOptions ¶ added in v1.2.0
type FactoryOptions struct {
// PersistentCachePath enables the cross-run positive cache when non-empty.
// When empty, the factory uses only the in-memory ValidationCache.
PersistentCachePath string
// PersistentCacheTTL is the freshness window for persistent entries.
// Zero means use the default (5 minutes).
PersistentCacheTTL time.Duration
// DisableCache disables both layers; validators will always hit the
// network. Used when the user passes --no-cache.
DisableCache bool
}
FactoryOptions configures the optional layers attached to a ValidatorFactory.
type FailureWhen ¶ added in v1.2.0
type GenericValidator ¶
type GenericValidator struct {
// contains filtered or unexported fields
}
func NewGenericValidatorWithClient ¶
func NewGenericValidatorWithClient(cfg ProviderConfig, httpClient *http.Client, limiter *client.RateLimiterManager) *GenericValidator
func (*GenericValidator) Config ¶ added in v1.2.1
func (v *GenericValidator) Config() ProviderConfig
Config returns a copy of the provider configuration so callers (e.g. the runner's retry budget) can read per-provider tuning fields without being able to mutate the validator's internal state.
func (*GenericValidator) FetchMetadata ¶ added in v1.0.9
func (v *GenericValidator) FetchMetadata(ctx context.Context, apiKey string, result *models.ValidationResult)
func (*GenericValidator) KeyPatterns ¶
func (v *GenericValidator) KeyPatterns() []string
func (*GenericValidator) Name ¶
func (v *GenericValidator) Name() string
func (*GenericValidator) SetCache ¶ added in v1.0.9
func (v *GenericValidator) SetCache(cache client.ResultCache)
func (*GenericValidator) SetCanaryCheck ¶ added in v1.0.8
func (v *GenericValidator) SetCanaryCheck(check bool)
func (*GenericValidator) SetSkipMetadata ¶ added in v1.0.8
func (v *GenericValidator) SetSkipMetadata(skip bool)
func (*GenericValidator) Validate ¶
func (v *GenericValidator) Validate(ctx context.Context, apiKey string) (*models.ValidationResult, error)
type LintIssue ¶ added in v1.2.1
type LintIssue struct {
Severity LintSeverity `json:"severity"`
Provider string `json:"provider,omitempty"`
Field string `json:"field,omitempty"`
Message string `json:"message"`
}
LintIssue is a single finding produced by LintProvider / LintAll.
func LintAll ¶ added in v1.2.1
func LintAll(configs []ProviderConfig) ([]LintIssue, bool)
LintAll validates every provider in the given configs and returns the combined issue list. The bool return is true when no errors were found.
func LintFile ¶ added in v1.2.1
LintFile reads and lints a YAML file (single file, multiple providers).
func LintProvider ¶ added in v1.2.1
func LintProvider(cfg ProviderConfig) []LintIssue
LintProvider runs all schema checks against one provider config.
type LintSeverity ¶ added in v1.2.1
type LintSeverity string
LintSeverity ranks issues. Errors block a run; warnings surface problems the user should know about but are not necessarily fatal.
const ( SeverityError LintSeverity = "error" SeverityWarning LintSeverity = "warning" )
type MetadataConfig ¶
type MetadataConfig struct {
URL string `yaml:"url"`
Method string `yaml:"method"`
Auth string `yaml:"auth"`
Headers map[string]string `yaml:"headers"`
BalancePath string `yaml:"balance_path"`
Extract string `yaml:"extract"`
StoreAs string `yaml:"store_as"`
RegexExtract string `yaml:"regex_extract"`
RegexExtractMatch int `yaml:"regex_extract_match"`
}
type MetadataFromValidation ¶
type MetadataFromValidation struct {
BalancePath string `yaml:"balance_path"`
BalanceSubtractPath string `yaml:"balance_subtract_path"`
NamePath string `yaml:"name_path"`
NameFallbackPath string `yaml:"name_fallback_path"`
EmailPath string `yaml:"email_path"`
QuotaPath string `yaml:"quota_path"`
CreditsPath string `yaml:"credits_path"`
VIPLevelPath string `yaml:"vip_level_path"`
TeamNamePath string `yaml:"team_name_path"`
UsernamePath string `yaml:"username_path"`
RegexExtract string `yaml:"regex_extract"`
RegexExtractMatch int `yaml:"regex_extract_match"`
}
type PatternEntry ¶
type PrefixEntry ¶
type PrefixIndex ¶ added in v1.0.5
type PrefixIndex map[string][]PrefixEntry
type PrefixTrie ¶ added in v1.1.0
type PrefixTrie struct {
// contains filtered or unexported fields
}
func NewPrefixTrie ¶ added in v1.1.0
func NewPrefixTrie() *PrefixTrie
func (*PrefixTrie) Add ¶ added in v1.1.0
func (t *PrefixTrie) Add(p *PrefixEntry)
func (*PrefixTrie) Build ¶ added in v1.1.0
func (t *PrefixTrie) Build()
func (*PrefixTrie) Search ¶ added in v1.1.0
func (t *PrefixTrie) Search(key string) []*PrefixEntry
type ProviderConfig ¶
type ProviderConfig struct {
Name string `yaml:"name"`
Category string `yaml:"category"`
KeyPrefixes []string `yaml:"key_prefixes"`
KeyPatterns []string `yaml:"key_patterns"`
SyntaxCheck string `yaml:"syntax_check,omitempty"`
CanaryPatterns []string `yaml:"canary_patterns,omitempty"`
Validation ValidationConfig `yaml:"validation"`
Metadata []MetadataConfig `yaml:"metadata,omitempty"`
MetadataFromValidation *MetadataFromValidation `yaml:"metadata_from_validation,omitempty"`
// Detection tunes how aggressively this provider matches unknown keys.
// MinScore, when > 0, requires the detector to score at least this high
// before reporting this provider as a match.
Detection *DetectionConfig `yaml:"detection,omitempty"`
// CacheTTLSeconds overrides the global positive-cache TTL for entries
// produced by this provider. Zero means "use the global default".
CacheTTLSeconds int `yaml:"cache_ttl_seconds,omitempty"`
// RetryPolicy overrides the global retry budget. MaxAttempts is total
// tries (1 = no retries). Backoff is exponential with cap.
RetryPolicy *RetryPolicy `yaml:"retry_policy,omitempty"`
// RegionalEndpoints lists alternative validation URLs to race against
// the primary validation.url. The first 200 wins and the endpoint that
// succeeded is recorded on the result.
RegionalEndpoints []EndpointConfig `yaml:"regional_endpoints,omitempty"`
IsCustom bool `yaml:"-"`
}
func InitValidatorsWithConfigs ¶
func InitValidatorsWithConfigs(proxy string, timeout int) (map[string]Validator, []ProviderConfig, *client.ProxyRotator, error)
func LoadProviderConfigs ¶
func LoadProviderConfigs() ([]ProviderConfig, error)
func LoadProviderFile ¶ added in v1.2.1
func LoadProviderFile(path string) ([]ProviderConfig, error)
LoadProviderFile reads and parses one provider YAML file. The file may contain a single provider or a YAML list of providers.
type ProviderInfo ¶
func FindProviderByName ¶ added in v1.0.3
func FindProviderByName(name string) ([]ProviderInfo, error)
func GetAllProviders ¶
func GetAllProviders() ([]ProviderInfo, error)
func GetProvidersByCategory ¶ added in v1.0.3
func GetProvidersByCategory(category string) ([]ProviderInfo, error)
type ResponseMatch ¶ added in v1.2.0
type RetryPolicy ¶ added in v1.2.1
type RetryPolicy struct {
MaxAttempts int `yaml:"max_attempts"`
OnStatus []int `yaml:"on_status,omitempty"`
InitialBackoffMs int `yaml:"initial_backoff_ms,omitempty"`
MaxBackoffMs int `yaml:"max_backoff_ms,omitempty"`
}
RetryPolicy is the per-provider retry behavior.
type ValidationConfig ¶
type ValidationConfig struct {
Method string `yaml:"method"`
URL string `yaml:"url"`
Auth string `yaml:"auth"`
Headers map[string]string `yaml:"headers"`
Body string `yaml:"body"`
Endpoints []EndpointConfig `yaml:"endpoints,omitempty"`
ErrorCheck *ErrorCheck `yaml:"error_check,omitempty"`
ExpectedStatus []int `yaml:"expected_status,omitempty"`
ResponseMatch *ResponseMatch `yaml:"response_match,omitempty"`
RetryOnStatus []int `yaml:"retry_on_status,omitempty"`
FailureWhen *FailureWhen `yaml:"failure_when,omitempty"`
}
type ValidatorFactory ¶ added in v1.0.8
type ValidatorFactory struct {
// contains filtered or unexported fields
}
func (*ValidatorFactory) Cache ¶ added in v1.0.9
func (f *ValidatorFactory) Cache() client.ResultCache
func (*ValidatorFactory) GetValidator ¶ added in v1.0.8
func (f *ValidatorFactory) GetValidator(name string) (Validator, bool)
func (*ValidatorFactory) RegisterConfig ¶ added in v1.2.1
func (f *ValidatorFactory) RegisterConfig(cfg ProviderConfig)
RegisterConfig adds (or replaces) a provider config in the factory. Used by tests to inject stub providers without mutating the global cached configs. Production code should rely on LoadProviderConfigs and the --templates flag instead.
func (*ValidatorFactory) SharedClient ¶ added in v1.1.0
func (f *ValidatorFactory) SharedClient() *http.Client
func (*ValidatorFactory) SharedLimiter ¶ added in v1.2.0
func (f *ValidatorFactory) SharedLimiter() *client.RateLimiterManager
SharedLimiter exposes the underlying RateLimiterManager so callers can install a global rate ceiling via SetGlobalLimit.