Skip to content

Commit

Permalink
output json schema errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mfenner committed Apr 19, 2024
1 parent d31e7c7 commit bfa2d7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 605 deletions.
19 changes: 15 additions & 4 deletions commonmeta/commonmeta.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package commonmeta

import (
"bytes"
"commonmeta/schemautils"
"commonmeta/types"
"encoding/json"
Expand All @@ -27,13 +28,23 @@ func WriteCommonmeta(data types.Data) ([]byte, []gojsonschema.ResultError) {
}

func WriteCommonmetaList(list []types.Data) ([]byte, []gojsonschema.ResultError) {
for _, data := range list {
o, err := json.Marshal(data)
if err != nil {
fmt.Println(err)
}
validation := schemautils.JSONSchemaErrors(o)
if !validation.Valid() {
var out bytes.Buffer
json.Indent(&out, o, "=", "\t")
fmt.Println(out.String())
return nil, validation.Errors()
}
}

output, err := json.Marshal(list)
if err != nil {
fmt.Println(err)
}
validation := schemautils.JSONSchemaErrors(output)
if !validation.Valid() {
return nil, validation.Errors()
}
return output, nil
}
Loading

0 comments on commit bfa2d7e

Please sign in to comment.