@@ -28,38 +28,42 @@ func ValidateOpenAPIDocument(doc libopenapi.Document) (bool, []*errors.Validatio
28
28
29
29
scErrs := jsch .Validate (decodedDocument )
30
30
31
+ var schemaValidationErrors []* errors.SchemaValidationFailure
32
+
31
33
if scErrs != nil {
32
- jk := scErrs .(* jsonschema.ValidationError )
33
34
34
- // flatten the validationErrors
35
- schFlatErrs := jk .BasicOutput ().Errors
36
- var schemaValidationErrors []* errors.SchemaValidationFailure
37
- for q := range schFlatErrs {
38
- er := schFlatErrs [q ]
39
- if er .KeywordLocation == "" || strings .HasPrefix (er .Error , "doesn't validate with" ) {
40
- continue // ignore this error, it's useless tbh, utter noise.
41
- }
42
- if er .Error != "" {
35
+ if jk , ok := scErrs .(* jsonschema.ValidationError ); ok {
43
36
44
- // locate the violated property in the schema
37
+ // flatten the validationErrors
38
+ schFlatErrs := jk .BasicOutput ().Errors
45
39
46
- located := LocateSchemaPropertyNodeByJSONPath (info .RootNode .Content [0 ], er .KeywordLocation )
47
- if located == nil {
48
- // try again with the instance location
49
- located = LocateSchemaPropertyNodeByJSONPath (info .RootNode .Content [0 ], er .InstanceLocation )
50
- }
51
- violation := & errors.SchemaValidationFailure {
52
- Reason : er .Error ,
53
- Location : er .KeywordLocation ,
54
- OriginalError : jk ,
40
+ for q := range schFlatErrs {
41
+ er := schFlatErrs [q ]
42
+ if er .KeywordLocation == "" || strings .HasPrefix (er .Error , "doesn't validate with" ) {
43
+ continue // ignore this error, it's useless tbh, utter noise.
55
44
}
56
- // if we have a location within the schema, add it to the error
57
- if located != nil {
58
- // location of the violation within the rendered schema.
59
- violation .Line = located .Line
60
- violation .Column = located .Column
45
+ if er .Error != "" {
46
+
47
+ // locate the violated property in the schema
48
+
49
+ located := LocateSchemaPropertyNodeByJSONPath (info .RootNode .Content [0 ], er .KeywordLocation )
50
+ if located == nil {
51
+ // try again with the instance location
52
+ located = LocateSchemaPropertyNodeByJSONPath (info .RootNode .Content [0 ], er .InstanceLocation )
53
+ }
54
+ violation := & errors.SchemaValidationFailure {
55
+ Reason : er .Error ,
56
+ Location : er .KeywordLocation ,
57
+ OriginalError : jk ,
58
+ }
59
+ // if we have a location within the schema, add it to the error
60
+ if located != nil {
61
+ // location of the violation within the rendered schema.
62
+ violation .Line = located .Line
63
+ violation .Column = located .Column
64
+ }
65
+ schemaValidationErrors = append (schemaValidationErrors , violation )
61
66
}
62
- schemaValidationErrors = append (schemaValidationErrors , violation )
63
67
}
64
68
}
65
69
0 commit comments