santhosh-tekuri / jsonschema

JSONSchema (draft 2020-12, draft 2019-09, draft-7, draft-6, draft-4) Validation using Go
Apache License 2.0
957 stars 98 forks source link

unknown $schema for schema loader #190

Closed sascha-andres closed 2 months ago

sascha-andres commented 2 months ago

I have the following schema defined:

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://xxxx/input.json",
    "title": "abc",
    "type": "object",
    "properties": {
 ... snip ...
}

I load it using a custom loader:

// EmbedFSLoader is responsible for loading schema data from an embedded filesystem.
type EmbedFSLoader struct{}

// Load retrieves the schema data and returns it as an io.ReadCloser. An error is returned if the schema cannot be obtained.
func (receiver EmbedFSLoader) Load(url string) (io.ReadCloser, error) {
    log.Print(url)
    d, err := GetSchema()
    if err != nil {
        return nil, err
    }
    return io.NopCloser(strings.NewReader(string(d))), nil
}

Now I wrote a test:

func TestSchemaLoader(t *testing.T) {
    loader.Register("regfeed", &EmbedFSLoader{})
    importSchema, err := jsonschema.Compile("regfeed://schema.json")
    if err != nil {
        t.Error(err)
    }
    if importSchema == nil {
        t.Error("schema is nil")
    }
}

Instead of succeeding I get the error unknown $schema "https://json-schema.org/draft/2020-12/schema" but you say you support this draft.

Any ideas what I make wrong?

santhosh-tekuri commented 2 months ago

Instead of succeeding I get the error unknown $schema "https://json-schema.org/draft/2020-12/schema" but you say you support this draft.

I don't see any such error message in the source code. it should say "unsupported draft" as shown in code

which version are you using. may be the error is coming from your code (not from the library)

sascha-andres commented 2 months ago

I am using 1.2.4, also jv cmdline prijt ths out:

❯ jv schema/schema.json
unknown $schema "https://json-schema.org/draft/2020-12/schema"

I also tested samples from https://json-schema.org/learn/json-schema-examples and they fail, too

sascha-andres commented 2 months ago

Thanks for your support, found the error, my fault, I just forgot to use v6 :/

Sometimes, only sometimes...