|
|
@ -4,7 +4,6 @@ import (
|
|
|
|
"encoding/json"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/santhosh-tekuri/jsonschema/v5"
|
|
|
|
"github.com/santhosh-tekuri/jsonschema/v5"
|
|
|
|
_ "github.com/santhosh-tekuri/jsonschema/v5/httploader"
|
|
|
|
_ "github.com/santhosh-tekuri/jsonschema/v5/httploader"
|
|
|
@ -33,7 +32,9 @@ func Validate(schemaURL string, r io.Reader) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func recurseDetails(detailed jsonschema.Detailed, acc []jsonschema.Detailed) []jsonschema.Detailed {
|
|
|
|
func recurseDetails(detailed jsonschema.Detailed, acc []jsonschema.Detailed) []jsonschema.Detailed {
|
|
|
|
|
|
|
|
if detailed.Error != "" {
|
|
|
|
acc = append(acc, detailed)
|
|
|
|
acc = append(acc, detailed)
|
|
|
|
|
|
|
|
}
|
|
|
|
for _, e := range detailed.Errors {
|
|
|
|
for _, e := range detailed.Errors {
|
|
|
|
acc = append(acc, recurseDetails(e, acc)...)
|
|
|
|
acc = append(acc, recurseDetails(e, acc)...)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -42,7 +43,6 @@ func recurseDetails(detailed jsonschema.Detailed, acc []jsonschema.Detailed) []j
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func PrettyDetails(w io.Writer, format string, details jsonschema.Detailed) error {
|
|
|
|
func PrettyDetails(w io.Writer, format string, details jsonschema.Detailed) error {
|
|
|
|
log.Printf("received format %q\n", format)
|
|
|
|
|
|
|
|
acc := make([]jsonschema.Detailed, 0)
|
|
|
|
acc := make([]jsonschema.Detailed, 0)
|
|
|
|
errors := recurseDetails(details, acc)
|
|
|
|
errors := recurseDetails(details, acc)
|
|
|
|
switch format {
|
|
|
|
switch format {
|
|
|
@ -53,9 +53,8 @@ func PrettyDetails(w io.Writer, format string, details jsonschema.Detailed) erro
|
|
|
|
return fmt.Errorf("error writing JSON payload to provided writer: %w", err)
|
|
|
|
return fmt.Errorf("error writing JSON payload to provided writer: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "markdown":
|
|
|
|
case "markdown":
|
|
|
|
fmt.Fprintf(w, "# Validation errors for \n")
|
|
|
|
fmt.Fprintf(w, "Valid|KeywordLocation|AbsoluteKeywordLocation|Instance Location|Error\n")
|
|
|
|
fmt.Fprintf(w, "Valid|KeywordLocation|AbsoluteKeywordLocation|Instance Location|Error")
|
|
|
|
fmt.Fprintf(w, "---|---|---|---|---\n")
|
|
|
|
fmt.Fprintf(w, "---|---|---|---|---")
|
|
|
|
|
|
|
|
for _, e := range errors {
|
|
|
|
for _, e := range errors {
|
|
|
|
fmt.Fprintf(w, "%t|%s|%s|%s|%s\n", e.Valid, e.KeywordLocation, e.AbsoluteKeywordLocation, e.InstanceLocation, e.Error)
|
|
|
|
fmt.Fprintf(w, "%t|%s|%s|%s|%s\n", e.Valid, e.KeywordLocation, e.AbsoluteKeywordLocation, e.InstanceLocation, e.Error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|