44package schema_validation
55
66import (
7+ "errors"
78 "fmt"
89 "github.com/pb33f/libopenapi"
9- "github.com/pb33f/libopenapi-validator/errors"
10+ liberrors "github.com/pb33f/libopenapi-validator/errors"
1011 "github.com/pb33f/libopenapi-validator/helpers"
1112 "github.com/santhosh-tekuri/jsonschema/v5"
1213 _ "github.com/santhosh-tekuri/jsonschema/v5/httploader"
@@ -16,11 +17,11 @@ import (
1617
1718// ValidateOpenAPIDocument will validate an OpenAPI document against the OpenAPI 2, 3.0 and 3.1 schemas (depending on version)
1819// It will return true if the document is valid, false if it is not and a slice of ValidationError pointers.
19- func ValidateOpenAPIDocument (doc libopenapi.Document ) (bool , []* errors .ValidationError ) {
20+ func ValidateOpenAPIDocument (doc libopenapi.Document ) (bool , []* liberrors .ValidationError ) {
2021
2122 info := doc .GetSpecInfo ()
2223 loadedSchema := info .APISchema
23- var validationErrors []* errors .ValidationError
24+ var validationErrors []* liberrors .ValidationError
2425 decodedDocument := * info .SpecJSON
2526
2627 compiler := jsonschema .NewCompiler ()
@@ -29,11 +30,12 @@ func ValidateOpenAPIDocument(doc libopenapi.Document) (bool, []*errors.Validatio
2930
3031 scErrs := jsch .Validate (decodedDocument )
3132
32- var schemaValidationErrors []* errors .SchemaValidationFailure
33+ var schemaValidationErrors []* liberrors .SchemaValidationFailure
3334
3435 if scErrs != nil {
3536
36- if jk , ok := scErrs .(* jsonschema.ValidationError ); ok {
37+ var jk * jsonschema.ValidationError
38+ if errors .As (scErrs , & jk ) {
3739
3840 // flatten the validationErrors
3941 schFlatErrs := jk .BasicOutput ().Errors
@@ -53,7 +55,7 @@ func ValidateOpenAPIDocument(doc libopenapi.Document) (bool, []*errors.Validatio
5355
5456 // locate the violated property in the schema
5557 located := LocateSchemaPropertyNodeByJSONPath (info .RootNode .Content [0 ], er .InstanceLocation )
56- violation := & errors .SchemaValidationFailure {
58+ violation := & liberrors .SchemaValidationFailure {
5759 Reason : er .Error ,
5860 Location : er .InstanceLocation ,
5961 DeepLocation : er .KeywordLocation ,
@@ -82,13 +84,13 @@ func ValidateOpenAPIDocument(doc libopenapi.Document) (bool, []*errors.Validatio
8284 }
8385
8486 // add the error to the list
85- validationErrors = append (validationErrors , & errors .ValidationError {
87+ validationErrors = append (validationErrors , & liberrors .ValidationError {
8688 ValidationType : helpers .Schema ,
8789 Message : "Document does not pass validation" ,
8890 Reason : fmt .Sprintf ("OpenAPI document is not valid according " +
8991 "to the %s specification" , info .Version ),
9092 SchemaValidationErrors : schemaValidationErrors ,
91- HowToFix : errors .HowToFixInvalidSchema ,
93+ HowToFix : liberrors .HowToFixInvalidSchema ,
9294 })
9395 }
9496 if len (validationErrors ) > 0 {
0 commit comments