Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

References not working? #97

Open
rbren opened this issue Mar 19, 2021 · 5 comments
Open

References not working? #97

rbren opened this issue Mar 19, 2021 · 5 comments

Comments

@rbren
Copy link
Contributor

rbren commented Mar 19, 2021

Seems like refs are not get resolved as they were in the previous version.

Environment

What is your OS and version?

What version of qri are you using (qri version)?

0.2.0

What version of Qri Desktop are you using?

What browser(s) did you use? What version?

Issue

What did you do?

package main

import (
    "context"
    "encoding/json"
    "fmt"

    "github.com/qri-io/jsonschema"
)

func main() {
    ctx := context.Background()
    var schemaData = []byte(`{
    "$id": "https://qri.io/schema/",
    "$comment" : "sample comment",
    "title": "Person",
    "type": "object",
    "definitions": {
        "age": {
            "type": "integer",
            "minimum": 0
        }
    },
    "properties": {
        "age": {"$ref": "#/definitions/age"}
    },
    "required": ["age"]
  }`)

    rs := &jsonschema.Schema{}
    if err := json.Unmarshal(schemaData, rs); err != nil {
        panic("unmarshal schema: " + err.Error())
    }
   var valid = []byte(`{
        "age": 10
    }`)
    errs, err := rs.ValidateBytes(ctx, valid)
    if err != nil {
        panic(err)
    }

    if len(errs) > 0 {
        fmt.Println(errs[0].Error())
    }
}

What happened?

/age: 10 failed to resolve schema for ref #/definitions/age

What did you expect to happen?

The same schemas work at https://www.jsonschemavalidator.net/

Please link any related issues.

Do you have a suggested fix?

@Arqu
Copy link
Contributor

Arqu commented Mar 19, 2021

As of draft2019_09 it should be $defs instead of definitions. Think definitions should be supported for backwards compatibility, but unsure if that works currently.

Let me know if this helps, I'll keep the issue open so I can come back to it sometime.

@bmfs
Copy link
Contributor

bmfs commented Apr 6, 2021

Wouldn't it be possible to just register definitions as a keyword using the jsonschemas.NewDefs handler for it to work in a compatible mode?

jsonschema.RegisterKeyword("definitions", jsonschema.NewDefs)
jsonschema.LoadDraft2019_09()

@Arqu
Copy link
Contributor

Arqu commented Apr 18, 2021

I don't think so, as far as I remember, there was a clash if you included both hence it also being disabled in tests. Happy to be wrong about it though if that's not the case.

@bmfs
Copy link
Contributor

bmfs commented Jul 14, 2021

I've used this approach and haven't detected any problem so far.

@rbren does it work for you?

@rbren
Copy link
Contributor Author

rbren commented Jul 14, 2021

I haven't been able to verify yet - still on the old version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants