Documentation
¶
Index ¶
- Constants
- func Flatten(outputUnit *jsonschema.OutputUnit) []*jsonschema.OutputUnit
- func GetNonSchemaError(result *ValidationResult) error
- func IsNonSchemaValidationError(result *ValidationResult) bool
- func WriteValidationResult(validationResult ValidationResult, outputFile string) (err error)
- func WriteValidationResults(validationResults []ValidationResult, outputFile string) (err error)
- type ValidationParams
- type ValidationResponse
- type ValidationResult
- func NewNonSchemaValidationError(err error, params *ValidationParams) *ValidationResult
- func NewValidationResult(validator *Validator, errors []ValidatorError) ValidationResult
- func NewValidationResultFromParams(params *ValidationParams, valErrs []ValidatorError) *ValidationResult
- func ValidateFromParams(params *ValidationParams) (*ValidationResult, error)
- type ValidationResultMetadata
- type Validator
- func (v *Validator) GetDocumentPath() string
- func (v *Validator) GetJsonModel() map[string]interface{}
- func (v *Validator) GetModelType() string
- func (v *Validator) GetSchemaVersion() string
- func (v *Validator) GetValidationParams() (*ValidationParams, error)
- func (v *Validator) GetValidationResult() (ValidationResult, error)
- func (v *Validator) IsLatestOscalVersion() (bool, error)
- func (v *Validator) SetDocumentPath(documentPath string)
- func (v *Validator) Validate() error
- type ValidatorError
Constants ¶
const (
NON_SCHEMA_ERROR_ABSOLUTE_KEYWORD_LOCATION = "non-schema-error"
)
Variables ¶
This section is empty.
Functions ¶
func Flatten ¶ added in v0.6.0
func Flatten(outputUnit *jsonschema.OutputUnit) []*jsonschema.OutputUnit
Flatten function to collect all OutputUnits into a slice
func GetNonSchemaError ¶ added in v0.6.0
func GetNonSchemaError(result *ValidationResult) error
GetNonSchemaError extracts the system validation error If the result is not a system validation error or if there are no errors, return nil
func IsNonSchemaValidationError ¶ added in v0.6.0
func IsNonSchemaValidationError(result *ValidationResult) bool
IsNonSchemaValidationError checks if the result is a system validation error
func WriteValidationResult ¶
func WriteValidationResult(validationResult ValidationResult, outputFile string) (err error)
WriteValidationResult writes a ValidationResult to a file
func WriteValidationResults ¶ added in v0.4.3
func WriteValidationResults(validationResults []ValidationResult, outputFile string) (err error)
WriteValidationResults writes a slice of ValidationResults to a file
Types ¶
type ValidationParams ¶ added in v0.6.0
type ValidationParams struct {
// This is the name of the model to validate (used for documentation and error reporting purposes) (required)
ModelType string `json:"model-type,omitempty" yaml:"model-type,omitempty"`
// This is the reference of the model to validate (does not have to be a url, used for documentation and error reporting purposes) (optional)
ModelPath string `json:"model-path,omitempty" yaml:"model-path,omitempty"`
// This is the version of the model to validate against (for example, 1.0.0) (optional)
ModelVersion string `json:"model-version,omitempty" yaml:"model-version,omitempty"`
// Must be a json map (map[string]interface{}) (required)
ModelData map[string]interface{} `json:"model-data,omitempty" yaml:"model-data,omitempty"`
// This is the reference of the schema to validate against (does not have to be a url, used for documentation and error reporting purposes) (required)
SchemaPath string `json:"schema-path,omitempty" yaml:"schema-path,omitempty"`
// Must be a json map (map[string]interface{}) (required)
SchemaData map[string]interface{} `json:"schema-data,omitempty" yaml:"schema-data,omitempty"`
// This is the version of the schema to validate against (for example, 1.0.0) (optional)
SchemaVersion string `json:"schema-version,omitempty" yaml:"schema-version,omitempty"`
}
type ValidationResponse ¶
type ValidationResponse struct {
Validator Validator
// Parsed validation result
Result ValidationResult
// Non-failing go-oscal warnings (ie: deprecated fields, newer schema versions, etc)
Warnings []string
// Unparsed Failing validation errors from the jsonschema library
JsonSchemaError *jsonschema.ValidationError
}
func ValidationCommand ¶
func ValidationCommand(inputFile string) (validationResponse ValidationResponse, err error)
ValidationCommand validates an OSCAL document Returns a ValidationResponse and an error
type ValidationResult ¶
type ValidationResult struct {
// Valid is true if the validation result is valid
Valid bool `json:"valid" yaml:"valid"`
// TimeStamp is the time the validation result was created
TimeStamp time.Time `json:"timeStamp" yaml:"timeStamp"`
// Errors is a slice of ValidatorErrors
Errors []ValidatorError `json:"errors,omitempty" yaml:"errors,omitempty"`
// Metadata is the metadata of the validation result
Metadata ValidationResultMetadata `json:"metadata" yaml:"metadata"`
}
func NewNonSchemaValidationError ¶ added in v0.6.0
func NewNonSchemaValidationError(err error, params *ValidationParams) *ValidationResult
NewNonSchemaValidationError creates a system validation error
func NewValidationResult ¶
func NewValidationResult(validator *Validator, errors []ValidatorError) ValidationResult
NewValidationResult creates a new ValidationResult from a Validator and a slice of ValidatorErrors
func NewValidationResultFromParams ¶ added in v0.6.0
func NewValidationResultFromParams(params *ValidationParams, valErrs []ValidatorError) *ValidationResult
NewValidationResultFromParams creates a new validation result from the params
func ValidateFromParams ¶ added in v0.6.0
func ValidateFromParams(params *ValidationParams) (*ValidationResult, error)
ValidateFromParams validates a model against a schema using the given `ValidationParams`
type ValidationResultMetadata ¶
type ValidationResultMetadata struct {
// DocumentPath is the path to the document
DocumentPath string `json:"documentPath,omitempty" yaml:"documentPath,omitempty"`
// DocumentType is the type of the document
DocumentType string `json:"documentType,omitempty" yaml:"documentType,omitempty"`
// DocumentVersion is the version of the document
DocumentVersion string `json:"documentVersion,omitempty" yaml:"documentVersion,omitempty"`
// SchemaVersion is the version of the schema
SchemaVersion string `json:"schemaVersion,omitempty" yaml:"schemaVersion,omitempty"`
}
func NewValidationResultMetadataFromParams ¶ added in v0.6.0
func NewValidationResultMetadataFromParams(params *ValidationParams) ValidationResultMetadata
NewValidationResultMetadataFromParams creates a new validation result metadata from the params
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
func NewValidator ¶
func NewValidator(oscalDoc model.InterfaceOrBytes) (validator Validator, err error)
NewValidator returns a validator with the models version of the schema.
func NewValidatorDesiredVersion ¶
func NewValidatorDesiredVersion(oscalDoc model.InterfaceOrBytes, desiredVersion string) (validator Validator, err error)
NewValidatorDesiredVersion returns a validator with the desired version of the schema.
func (*Validator) GetDocumentPath ¶
GetDocumentPath returns the path of the document being validated.
func (*Validator) GetJsonModel ¶
GetJsonModel returns the model being validated.
func (*Validator) GetModelType ¶
GetModelType returns the type of the model being validated.
func (*Validator) GetSchemaVersion ¶
GetSchemaVersion returns the version of the schema used to validate the model.
func (*Validator) GetValidationParams ¶ added in v0.6.0
func (v *Validator) GetValidationParams() (*ValidationParams, error)
GetValidationParams returns the validation params for the validator.
func (*Validator) GetValidationResult ¶
func (v *Validator) GetValidationResult() (ValidationResult, error)
GetValidationResult returns a ValidationResult. If the validation has not been run, an error is returned.
func (*Validator) IsLatestOscalVersion ¶
IsLatestOscalVersion returns true if the model is the latest version of the OSCAL schema.
func (*Validator) SetDocumentPath ¶
SetDocumentPath sets the path of the document being validated.
type ValidatorError ¶
type ValidatorError struct {
// KeywordLocation is the location of the keyword in the schema for failing value
KeywordLocation string `json:"keywordLocation" yaml:"keywordLocation"`
// AbsoluteKeywordLocation is the absolute location of the keyword in the schema for failing value
AbsoluteKeywordLocation string `json:"absoluteKeywordLocation" yaml:"absoluteKeywordLocation"`
// InstanceLocation is the location of the instance in the document
InstanceLocation string `json:"instanceLocation" yaml:"instanceLocation"`
// Error is the error message
Error string `json:"error" yaml:"error"`
// FailedValue is the value of the key that failed validation
FailedValue interface{} `json:"failedValue,omitempty" yaml:"failedValue,omitempty"`
}
Extension of the jsonschema.BasicError struct to include the failed value if the failed value is a map or slice, it will be omitted
func ExtractErrors ¶
func ExtractErrors(originalObject map[string]interface{}, detailedOutputUnit *jsonschema.OutputUnit) (validationErrors []ValidatorError)
Creates a []ValidatorError from a jsonschema.OutputUnit The jsonschema.OutputUnit contains the errors from the validation