Skip to content

Commit e95f17b

Browse files
authored
make json schema validation multi-error sorted (#96)
1 parent 916303e commit e95f17b

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

schema_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestNewSchema(t *testing.T) {
3939
name: "json schema validation for header failed",
4040
schema: `{"parser_settings": {"versionx": "9999", "file_format_type": "exe" }}`,
4141
exts: nil,
42-
err: "schema 'test-schema' validation failed:\nparser_settings: version is required\nparser_settings: Additional property versionx is not allowed",
42+
err: "schema 'test-schema' validation failed:\nparser_settings: Additional property versionx is not allowed\nparser_settings: version is required",
4343
},
4444
{
4545
name: "no supported schema handler",

validation/jsonvalidate.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package validation
44

55
import (
66
"fmt"
7+
"sort"
78
"strings"
89

910
"github.com/xeipuuv/gojsonschema"
@@ -25,6 +26,7 @@ func SchemaValidate(schemaName string, schemaContent []byte, jsonSchema string)
2526
for _, err := range result.Errors() {
2627
errs = append(errs, err.String())
2728
}
29+
sort.Strings(errs)
2830
if len(errs) == 1 {
2931
return fmt.Errorf("schema '%s' validation failed: %s", schemaName, errs[0])
3032
}

validation/jsonvalidate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestSchemaValidate(t *testing.T) {
5757
"unknown": "blah"
5858
}
5959
}`,
60-
expectedErr: "schema 'test-schema' validation failed:\nparser_settings: file_format_type is required\nparser_settings: Additional property unknown is not allowed",
60+
expectedErr: "schema 'test-schema' validation failed:\nparser_settings: Additional property unknown is not allowed\nparser_settings: file_format_type is required",
6161
},
6262
} {
6363
t.Run(test.name, func(t *testing.T) {

0 commit comments

Comments
 (0)