@@ -9,29 +9,27 @@ import (
99 "github.com/santhosh-tekuri/jsonschema/v6"
1010)
1111
12- // SchemaValidationFailure is a wrapper around the jsonschema.ValidationError object, to provide a more
13- // user-friendly way to break down what went wrong.
12+ // SchemaValidationFailure describes any failure that occurs when validating data
13+ // against either an OpenAPI or JSON Schema. It aims to be a more user-friendly
14+ // representation of the error than what is provided by the jsonschema library.
1415type SchemaValidationFailure struct {
1516 // Reason is a human-readable message describing the reason for the error.
1617 Reason string `json:"reason,omitempty" yaml:"reason,omitempty"`
1718
18- // Location is the XPath-like location of the validation failure
19- Location string `json:"location ,omitempty" yaml:"location ,omitempty"`
19+ // InstancePath is the raw path segments from the root to the failing field
20+ InstancePath [] string `json:"instancePath ,omitempty" yaml:"instancePath ,omitempty"`
2021
2122 // FieldName is the name of the specific field that failed validation (last segment of the path)
2223 FieldName string `json:"fieldName,omitempty" yaml:"fieldName,omitempty"`
2324
24- // FieldPath is the JSONPath representation of the field location (e.g., "$.user.email")
25+ // FieldPath is the JSONPath representation of the field location that failed validation (e.g., "$.user.email")
2526 FieldPath string `json:"fieldPath,omitempty" yaml:"fieldPath,omitempty"`
2627
27- // InstancePath is the raw path segments from the root to the failing field
28- InstancePath []string `json:"instancePath,omitempty" yaml:"instancePath,omitempty"`
29-
30- // DeepLocation is the path to the validation failure as exposed by the jsonschema library.
31- DeepLocation string `json:"deepLocation,omitempty" yaml:"deepLocation,omitempty"`
28+ // KeywordLocation is the relative path to the JsonSchema keyword that failed validation
29+ KeywordLocation string `json:"keywordLocation,omitempty" yaml:"keywordLocation,omitempty"`
3230
33- // AbsoluteLocation is the absolute path to the validation failure as exposed by the jsonschema library.
34- AbsoluteLocation string `json:"absoluteLocation ,omitempty" yaml:"absoluteLocation ,omitempty"`
31+ // AbsoluteKeywordLocation is the absolute path to the validation failure as exposed by the jsonschema library.
32+ AbsoluteKeywordLocation string `json:"absoluteKeywordLocation ,omitempty" yaml:"absoluteKeywordLocation ,omitempty"`
3533
3634 // Line is the line number where the violation occurred. This may a local line number
3735 // if the validation is a schema (only schemas are validated locally, so the line number will be relative to
@@ -46,14 +44,15 @@ type SchemaValidationFailure struct {
4644 // ReferenceSchema is the schema that was referenced in the validation failure.
4745 ReferenceSchema string `json:"referenceSchema,omitempty" yaml:"referenceSchema,omitempty"`
4846
49- // ReferenceObject is the object that was referenced in the validation failure.
47+ // ReferenceObject is the object that failed schema validation
5048 ReferenceObject string `json:"referenceObject,omitempty" yaml:"referenceObject,omitempty"`
5149
52- // ReferenceExample is an example object generated from the schema that was referenced in the validation failure .
53- ReferenceExample string `json:"referenceExample,omitempty " yaml:"referenceExample,omitempty "`
50+ // The original jsonschema.ValidationError object, if the schema failure originated from the jsonschema library .
51+ OriginalJsonSchemaError * jsonschema. ValidationError `json:"- " yaml:"- "`
5452
55- // The original error object, which is a jsonschema.ValidationError object.
56- OriginalError * jsonschema.ValidationError `json:"-" yaml:"-"`
53+ // DEPRECATED in favor of explicit use of FieldPath & InstancePath
54+ // Location is the XPath-like location of the validation failure
55+ Location string `json:"location,omitempty" yaml:"location,omitempty"`
5756}
5857
5958// Error returns a string representation of the error
@@ -97,7 +96,7 @@ type ValidationError struct {
9796 ParameterName string `json:"parameterName,omitempty" yaml:"parameterName,omitempty"`
9897
9998 // SchemaValidationErrors is a slice of SchemaValidationFailure objects that describe the validation errors
100- // This is only populated whe the validation type is against a schema.
99+ // This is only populated when the validation type is against a schema.
101100 SchemaValidationErrors []* SchemaValidationFailure `json:"validationErrors,omitempty" yaml:"validationErrors,omitempty"`
102101
103102 // Context is the object that the validation error occurred on. This is usually a pointer to a schema
0 commit comments