santhosh-tekuri/jsonschema

Support for HTTP references

yannh opened this issue · 3 comments

yannh commented

Hello! I maintain a repository of JSON Schemas for Kubernetes, forked from an older project - which for better (or worse) contains HTTP references, like here: https://github.com/yannh/kubernetes-json-schema/blob/ded4ffd7cdc4f5564af13a684620cd7e962bd560/v1.26.0/deployment.json#L22

Am I looking at the right place, to assume that this is not supported by this library yet?

"file": loadFileURL,

It is currently throwing the following error:
error: jsonschema https://kubernetesjsonschema.dev/master/replicationcontroller-v1.json compilation failed: no Loader found for https://kubernetesjsonschema.dev/master/_definitions.json

Is this something you would consider adding support for? I am interested in this to keep full backward compatibility for Kubeconform (WIP PR yannh/kubeconform#168) - even though by default it uses files without those HTTP references and I am not sure if people actually do use the files with references.

Many thanks!

http references are supported. it is mentioned in README. below code shows how to do it:

package main

import (
	"fmt"

	"github.com/santhosh-tekuri/jsonschema/v5"
	_ "github.com/santhosh-tekuri/jsonschema/v5/httploader"
)

func main() {
	u := "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/ded4ffd7cdc4f5564af13a684620cd7e962bd560/v1.26.0/deployment.json"
	_, err := jsonschema.Compile(u)
	fmt.Println("error: ", err)
}

you need to add following import:

import _ "github.com/santhosh-tekuri/jsonschema/v5/httploader"

yannh commented

Thanks a lot for the support! This worked ❤️