|
|
@ -1,6 +1,7 @@
|
|
|
|
package obp
|
|
|
|
package obp
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
|
|
|
@ -9,6 +10,14 @@ import (
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type PrettyDetailFormat int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
|
|
JSON = iota
|
|
|
|
|
|
|
|
Markdown
|
|
|
|
|
|
|
|
CSV
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func Validate(schemaURL string, r io.Reader) error {
|
|
|
|
func Validate(schemaURL string, r io.Reader) error {
|
|
|
|
var m interface{}
|
|
|
|
var m interface{}
|
|
|
|
|
|
|
|
|
|
|
@ -29,3 +38,30 @@ func Validate(schemaURL string, r io.Reader) error {
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func recurseDetails(detailed jsonschema.Detailed, acc []jsonschema.Detailed) []jsonschema.Detailed {
|
|
|
|
|
|
|
|
acc = append(acc, detailed)
|
|
|
|
|
|
|
|
for _, e := range detailed.Errors {
|
|
|
|
|
|
|
|
acc = append(acc, recurseDetails(e, acc)...)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return acc
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func PrettyDetails(w io.Writer, format PrettyDetailFormat, details jsonschema.Detailed) error {
|
|
|
|
|
|
|
|
acc := make([]jsonschema.Detailed, 0)
|
|
|
|
|
|
|
|
errors := recurseDetails(details, acc)
|
|
|
|
|
|
|
|
switch format {
|
|
|
|
|
|
|
|
case JSON:
|
|
|
|
|
|
|
|
enc := json.NewEncoder(w)
|
|
|
|
|
|
|
|
err := enc.Encode(errors)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return fmt.Errorf("error writing JSON payload to provided writer: %w", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return fmt.Errorf("unknown format")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|