Documentation
¶
Index ¶
- Variables
- func JSONSchemaValidate(schemaURL string, docJSON []byte) (bool, error)
- func JSONSchemaValidateWithPositions(schemaURL string, docJSON []byte, posMap map[string]SourcePosition) (bool, error)
- func ValidateXSD(b []byte, schemaPath string) (bool, error)
- type CsvValidator
- type EditorConfigValidator
- type EnvValidator
- type HclValidator
- type HoconValidator
- type IniValidator
- type JSONCValidator
- type JSONMarshaler
- type JSONValidator
- type JustfileValidator
- type KdlValidator
- type PlistValidator
- type PropValidator
- type SarifValidator
- type SchemaErrorPosition
- type SchemaErrors
- type SchemaValidator
- type SourcePosition
- type TomlValidator
- type ToonValidator
- type ValidationError
- type Validator
- type XMLSchemaValidator
- type XMLValidator
- type YAMLValidator
Constants ¶
This section is empty.
Variables ¶
var ErrNoSchema = errors.New("no schema declared")
ErrNoSchema is returned by SchemaValidator.ValidateSchema when the document supports schema validation but does not declare a schema.
Functions ¶
func JSONSchemaValidateWithPositions ¶ added in v2.2.0
func JSONSchemaValidateWithPositions(schemaURL string, docJSON []byte, posMap map[string]SourcePosition) (bool, error)
JSONSchemaValidateWithPositions validates docJSON against schemaURL and annotates errors with source positions from posMap. The map keys are gojsonschema context strings like "(root).name".
Types ¶
type CsvValidator ¶
CsvValidator validates CSV files. Zero-value fields use Go's csv defaults (comma delimiter, no comment character, strict quotes).
func (CsvValidator) ValidateSyntax ¶
func (v CsvValidator) ValidateSyntax(b []byte) (bool, error)
ValidateSyntax checks if the provided byte slice represents a valid .csv file. https://pkg.go.dev/encoding/csv
type EditorConfigValidator ¶
type EditorConfigValidator struct{}
func (EditorConfigValidator) ValidateSyntax ¶
func (EditorConfigValidator) ValidateSyntax(b []byte) (bool, error)
Validate implements the Validator interface by attempting to parse a byte array of an editorconfig file using editorconfig-core-go package
type EnvValidator ¶
type EnvValidator struct{}
func (EnvValidator) ValidateSyntax ¶
func (EnvValidator) ValidateSyntax(b []byte) (bool, error)
Validate implements the Validator interface by attempting to parse a byte array of a env file using envparse package
type HclValidator ¶
type HclValidator struct{}
HclValidator is used to validate a byte slice that is intended to represent a HashiCorp Configuration Language (HCL) file.
func (HclValidator) ValidateSyntax ¶
func (HclValidator) ValidateSyntax(b []byte) (bool, error)
Validate checks if the provided byte slice represents a valid .hcl file.
The hcl parser uses FIFO to determine which error to display to the user. For more information, see the documentation at:
https://pkg.go.dev/github.com/hashicorp/hcl/v2#Diagnostics.Error
If the hcl.Diagnostics slice contains more than one error, the wrapped error returned by this function will include them as "and {count} other diagnostic(s)" in the error message.
type HoconValidator ¶
type HoconValidator struct{}
HoconValidator is used to validate a byte slice that is intended to represent a HOCON file.
func (HoconValidator) ValidateSyntax ¶
func (HoconValidator) ValidateSyntax(b []byte) (bool, error)
Validate checks if the provided byte slice represents a valid .hocon file.
type IniValidator ¶
type IniValidator struct {
ForbidDuplicateKeys bool
}
IniValidator validates INI files. When ForbidDuplicateKeys is true, duplicate keys within the same section are reported as errors.
func (IniValidator) ValidateSyntax ¶
func (v IniValidator) ValidateSyntax(b []byte) (bool, error)
type JSONCValidator ¶ added in v2.2.0
type JSONCValidator struct{}
func (JSONCValidator) MarshalToJSON ¶ added in v2.2.0
func (JSONCValidator) MarshalToJSON(b []byte) ([]byte, error)
func (JSONCValidator) ValidateSchema ¶ added in v2.2.0
func (JSONCValidator) ValidateSchema(b []byte, filePath string) (bool, error)
func (JSONCValidator) ValidateSyntax ¶ added in v2.2.0
func (JSONCValidator) ValidateSyntax(b []byte) (bool, error)
type JSONMarshaler ¶
JSONMarshaler is an optional interface for validators whose content can be converted to JSON for schema validation. This is used when an external schema (e.g. from SchemaStore or --schema-map) is applied to a file that does not declare its own $schema.
type JSONValidator ¶
type JSONValidator struct {
ForbidDuplicateKeys bool
}
JSONValidator validates JSON files. When ForbidDuplicateKeys is true, duplicate keys in objects are reported as errors.
func (JSONValidator) MarshalToJSON ¶
func (JSONValidator) MarshalToJSON(b []byte) ([]byte, error)
func (JSONValidator) ValidateSchema ¶
func (JSONValidator) ValidateSchema(b []byte, filePath string) (bool, error)
func (JSONValidator) ValidateSyntax ¶
func (v JSONValidator) ValidateSyntax(b []byte) (bool, error)
type JustfileValidator ¶ added in v2.2.0
type JustfileValidator struct{}
func (JustfileValidator) ValidateSyntax ¶ added in v2.2.0
func (JustfileValidator) ValidateSyntax(b []byte) (bool, error)
type KdlValidator ¶ added in v2.2.2
type KdlValidator struct{}
KdlValidator validates KDL Document Language files via the sblinch/kdl-go parser. It implements ValidateSyntax only — KDL has no schema system, so it does not implement SchemaValidator.
See https://kdl.dev/ for the KDL spec.
func (KdlValidator) ValidateSyntax ¶ added in v2.2.2
func (KdlValidator) ValidateSyntax(b []byte) (bool, error)
type PlistValidator ¶
type PlistValidator struct{}
PlistValidator is used to validate a byte slice that is intended to represent a Apple Property List file (plist).
func (PlistValidator) ValidateSyntax ¶
func (PlistValidator) ValidateSyntax(b []byte) (bool, error)
Validate checks if the provided byte slice represents a valid .plist file.
type PropValidator ¶
type PropValidator struct{}
func (PropValidator) ValidateSyntax ¶
func (PropValidator) ValidateSyntax(b []byte) (bool, error)
Validate implements the Validator interface by attempting to parse a byte array of properties
type SarifValidator ¶
type SarifValidator struct{}
func (SarifValidator) ValidateSchema ¶
func (SarifValidator) ValidateSchema(b []byte, _ string) (bool, error)
func (SarifValidator) ValidateSyntax ¶
func (SarifValidator) ValidateSyntax(b []byte) (bool, error)
type SchemaErrorPosition ¶ added in v2.2.0
SchemaErrorPosition holds the source position for a single schema error.
type SchemaErrors ¶
type SchemaErrors struct {
Prefix string
Items []string
Positions []SchemaErrorPosition
}
SchemaErrors holds multiple schema validation errors. The joined Error() string is used for backward compatibility, while Errors() returns individual error messages. Positions is parallel to Items — Positions[i] is the source position for Items[i]. A zero-value position means the location is unknown.
func (*SchemaErrors) Error ¶
func (e *SchemaErrors) Error() string
func (*SchemaErrors) Errors ¶
func (e *SchemaErrors) Errors() []string
type SchemaValidator ¶
SchemaValidator is an optional interface for validators that support schema validation. The filePath parameter is the absolute path to the file being validated, used to resolve relative schema references. ValidateSchema should return ErrNoSchema when the document does not declare a schema (e.g. no $schema property in JSON).
type SourcePosition ¶ added in v2.2.0
SourcePosition holds a 1-based line and column in the original source file.
type TomlValidator ¶
type TomlValidator struct{}
func (TomlValidator) MarshalToJSON ¶
func (TomlValidator) MarshalToJSON(b []byte) ([]byte, error)
func (TomlValidator) ValidateSchema ¶
func (TomlValidator) ValidateSchema(b []byte, filePath string) (bool, error)
func (TomlValidator) ValidateSyntax ¶
func (TomlValidator) ValidateSyntax(b []byte) (bool, error)
type ToonValidator ¶
type ToonValidator struct{}
func (ToonValidator) MarshalToJSON ¶
func (ToonValidator) MarshalToJSON(b []byte) ([]byte, error)
func (ToonValidator) ValidateSchema ¶
func (ToonValidator) ValidateSchema(b []byte, filePath string) (bool, error)
func (ToonValidator) ValidateSyntax ¶
func (ToonValidator) ValidateSyntax(b []byte) (bool, error)
type ValidationError ¶
ValidationError wraps a validation error with optional source position. Line and Column are 1-based. A zero value means the position is unknown.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error
type Validator ¶
Validator is the base interface that all validators must implement. For optional capabilities, use type assertions against SchemaValidator.
type XMLSchemaValidator ¶
XMLSchemaValidator is a marker interface for validators that use XSD schema validation instead of JSON Schema. When an external schema is applied via --schema-map or --schemastore, the CLI uses ValidateXSD instead of JSONSchemaValidate.
type XMLValidator ¶
type XMLValidator struct{}
func (XMLValidator) ValidateSchema ¶
func (XMLValidator) ValidateSchema(b []byte, filePath string) (bool, error)
func (XMLValidator) ValidateSyntax ¶
func (XMLValidator) ValidateSyntax(b []byte) (bool, error)
func (XMLValidator) ValidateXSD ¶
func (XMLValidator) ValidateXSD(b []byte, schemaPath string) (bool, error)
ValidateXSD satisfies the XMLSchemaValidator marker interface.
type YAMLValidator ¶
type YAMLValidator struct{}
YAMLValidator validates YAML files. Note: yaml.v3 already rejects duplicate keys by default.
func (YAMLValidator) MarshalToJSON ¶
func (YAMLValidator) MarshalToJSON(b []byte) ([]byte, error)
func (YAMLValidator) ValidateSchema ¶
func (YAMLValidator) ValidateSchema(b []byte, filePath string) (bool, error)
func (YAMLValidator) ValidateSyntax ¶
func (YAMLValidator) ValidateSyntax(b []byte) (bool, error)