Documentation
¶
Index ¶
- func CasingOptions(rc RuleCheck) string
- func EnumerationOptions(rc RuleCheck) []string
- func LengthOptions(rc RuleCheck) (minVal, maxVal *int)
- func LookupNativeRule(spectralName string) (string, bool)
- func PatternOptions(rc RuleCheck) (match, notMatch string)
- func PropertyOptions(rc RuleCheck) []string
- type ExtendsEntry
- type GenerateOption
- type GenerateOptions
- type GenerateResult
- type IntermediateConfig
- type JSONPathMapping
- type Rule
- type RuleCheck
- type Warning
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CasingOptions ¶
CasingOptions extracts the case type from a RuleCheck's FunctionOptions.
func EnumerationOptions ¶
EnumerationOptions extracts allowed values from a RuleCheck's FunctionOptions.
func LengthOptions ¶
LengthOptions extracts min/max from a RuleCheck's FunctionOptions.
func LookupNativeRule ¶
LookupNativeRule maps a Spectral/Vacuum rule name to a native rule ID. Returns the native ID and true if found, or empty string and false if not mapped.
func PatternOptions ¶
PatternOptions extracts match/notMatch from a RuleCheck's FunctionOptions.
func PropertyOptions ¶
PropertyOptions extracts properties from xor/or RuleCheck's FunctionOptions.
Types ¶
type ExtendsEntry ¶
type ExtendsEntry struct {
Name string // e.g., "spectral:oas", "speakeasy-recommended"
Modifier string // e.g., "all", "recommended", "off" (empty if not specified)
}
ExtendsEntry stores the raw extends value from the source config. Known Name values by format:
Spectral: "spectral:oas", "spectral:asyncapi" Legacy: "speakeasy-recommended", "speakeasy-generation"
Known Modifier values (Spectral only, empty for Legacy):
"all" - enable all rules from the extended ruleset "recommended" - enable only recommended rules "off" - disable the extended ruleset entirely
type GenerateOption ¶
type GenerateOption func(*GenerateOptions)
GenerateOption is a functional option for Generate.
func WithRulePrefix ¶
func WithRulePrefix(prefix string) GenerateOption
WithRulePrefix sets the rule ID prefix.
func WithRulesDir ¶
func WithRulesDir(dir string) GenerateOption
WithRulesDir sets the rules directory.
type GenerateOptions ¶
type GenerateOptions struct {
// RulesDir is the relative path for .ts files in config (default "./rules").
RulesDir string
// RulePrefix is the prefix for generated rule IDs (default "custom-").
RulePrefix string
}
GenerateOptions configures the output generation.
type GenerateResult ¶
type GenerateResult struct {
// Config is the native lint config, serializable to YAML.
Config *linter.Config
// GeneratedRules maps ruleID -> TypeScript source code.
GeneratedRules map[string]string
// Warnings from the generation phase.
Warnings []Warning
// contains filtered or unexported fields
}
GenerateResult holds all generated output.
func Generate ¶
func Generate(ir *IntermediateConfig, opts ...GenerateOption) (*GenerateResult, error)
Generate converts an IntermediateConfig into native linter output. This is stage 2 of the pipeline — all native-format-specific interpretation happens here.
func (*GenerateResult) WriteFiles ¶
func (r *GenerateResult) WriteFiles(outputDir string) error
WriteFiles writes lint.yaml and rules/*.ts to the output directory.
type IntermediateConfig ¶
type IntermediateConfig struct {
// Extends stores the raw extends values from the source config.
// Examples: ["spectral:oas"], ["speakeasy-recommended"]
// Interpretation of these values is left to the consumer (Generate maps them).
Extends []ExtendsEntry
// Rules is the unified list of all rules from the source config.
// Each rule is either a severity-only override or a full rule definition.
// Parse does NOT classify rules as "builtin" vs "custom" — that's a
// consumer concern. Rules with Given/Then populated are custom rules;
// rules with only Severity set are overrides.
Rules []Rule
// Warnings collected during parsing (malformed entries, etc.)
Warnings []Warning
}
IntermediateConfig is the format-agnostic intermediate representation. Parse Spectral/Vacuum/Legacy configs into this, then pass to Generate() or consume directly in other projects.
func Parse ¶
func Parse(r io.Reader) (*IntermediateConfig, error)
Parse reads a Spectral, Vacuum, or Legacy Speakeasy config and returns the intermediate representation. Parse is lenient: it collects as many rules as possible and adds warnings for malformed entries rather than failing entirely.
func ParseFile ¶
func ParseFile(path string) (*IntermediateConfig, error)
ParseFile reads a config file and returns the intermediate representation.
type JSONPathMapping ¶
type JSONPathMapping struct {
// Collection is the index collection name (e.g., "operations", "inlinePathItems").
// Empty for direct document access patterns.
Collection string
// IsKeyAccess is true when the ~ operator is used (extract map key).
IsKeyAccess bool
// FieldAccess is a field to extract from each node (e.g., "url" for $.servers[*].url).
FieldAccess string
// Filter is a filter expression stripped during structural matching,
// to be re-applied as generated TypeScript.
Filter string
// HTTPMethod is set when matching $.paths[*].{method} patterns.
HTTPMethod string
// IsDirect is true when the path targets a single document location
// (e.g., $.info, $.components) rather than an indexed collection.
IsDirect bool
// DirectAccess is the TypeScript expression for direct access.
DirectAccess string
// Unsupported is true when the JSONPath could not be mapped.
Unsupported bool
// OriginalPath is the original JSONPath expression.
OriginalPath string
}
JSONPathMapping represents the result of mapping a JSONPath to an index collection and generated TypeScript code.
func MapJSONPath ¶
func MapJSONPath(path string) JSONPathMapping
MapJSONPath maps a JSONPath expression to an index collection and access pattern.
The mapper uses structural matching: 1. Strip filter expressions [?(...)] from the path 2. Strip the ~ (key name) operator 3. Match the structural path against known patterns 4. Return mapping info for code generation
Note on ~ operator: The ~ suffix in JSONPath (e.g., $.paths[*]~) is a Spectral extension, not standard JSONPath. It extracts the map key rather than the value.
type Rule ¶
type Rule struct {
ID string // rule name/ID from source config
Description string // rule description
Message string // message template with {{placeholders}}
Severity string // normalized severity (see doc comment above)
Resolved *bool // nil = default (resolved), false = unresolved
Formats []string // "oas2", "oas3", "oas3.0", "oas3.1"
Source string // ruleset name this rule came from (for dedup tracing)
Given []string // JSONPath expressions (empty for overrides)
Then []RuleCheck // checks to apply (empty for overrides)
}
Rule is a unified representation of any rule from a source config. Severity-only overrides have Given/Then empty. Full custom rules have Given/Then populated.
Severity is normalized during parsing to canonical values:
"error", "warn", "info", "hint", "off"
Numeric severities from Spectral (0=error, 1=warn, 2=info, 3=hint) are normalized to their string equivalents.
func (*Rule) IsDisabled ¶
IsDisabled returns true if severity is "off".
func (*Rule) IsOverride ¶
IsOverride returns true if this rule is a severity-only override (no given/then logic).
type RuleCheck ¶
type RuleCheck struct {
Field string // field to check (empty = check the node itself)
Function string // "truthy", "pattern", "enumeration", etc.
FunctionOptions map[string]any // function-specific options (documented above)
Message string // per-check message override
}
RuleCheck is a single function application from a "then" clause. FunctionOptions shape depends on Function:
- "pattern": { "match": string, "notMatch": string }
- "enumeration": { "values": []string }
- "length": { "min": number, "max": number }
- "casing": { "type": string, "disallowDigits": bool, "separator": { "char": string } }
- "alphabetical":{ "keyedBy": string }
- "schema": { "schema": object, "dialect": string, "allErrors": bool }
- "xor"/"or": { "properties": []string }
- "truthy"/"falsy"/"defined"/"undefined"/"typedEnum": (no options)