Force Draft version of JsonSchema (#221)

* Force Draft version of JsonSchema
* Add test validating using CRD that misses explicit draft version
This commit is contained in:
Yann Hamon 2023-07-16 09:42:11 +02:00 committed by GitHub
parent 278385f4c9
commit ae67bb4709
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View file

@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"strings"
jsonschema "github.com/santhosh-tekuri/jsonschema/v5"
_ "github.com/santhosh-tekuri/jsonschema/v5/httploader"
@ -254,7 +255,12 @@ func downloadSchema(registries []registry.Registry, kind, version, k8sVersion st
for _, reg := range registries {
path, schemaBytes, err = reg.DownloadSchema(kind, version, k8sVersion)
if err == nil {
schema, err := jsonschema.CompileString(path, string(schemaBytes))
c := jsonschema.NewCompiler()
c.Draft = jsonschema.Draft4
if err := c.AddResource(path, strings.NewReader(string(schemaBytes))); err != nil {
continue
}
schema, err := c.Compile(path)
// If we got a non-parseable response, we try the next registry
if err != nil {
continue