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

Path must begin with a leading "/" #123

Open
glasserc opened this issue Oct 28, 2021 · 0 comments
Open

Path must begin with a leading "/" #123

glasserc opened this issue Oct 28, 2021 · 0 comments

Comments

@glasserc
Copy link

Hi! I'm using json_schema indirectly through https://github.com/thoughtbot/json_matchers so this might not be the right place to report this.

I have a question about reference URLs. The following code fails:

# frozen_string_literal: true

require "json_schema"

store = JsonSchema::DocumentStore.new

foo_schema = JsonSchema.parse!(
  {
    "id" => "file:/foo.json",
    "type" => "object",
    "properties" => {
      "a" => {
        "type" => "string"
      }
    }
  }
)

store.add_schema(foo_schema)

bar_schema = JsonSchema.parse!(
  {
    "id" => "file:/bar.json",
    "type" => "object",
    "properties" => {
      "foo" => {
        "$ref" => "file:/foo.json",
      }
    }
  }
)

bar_schema.expand_references!(store: store)

bar_schema.validate!(
  {
    foo: {
      a: 1
    }
  }
)

However, as a workaround, my team discovered that putting # at the end of foo id and the $ref seems to work.

Tracing through the code I found this reference:

# given a simple fragment without '#', resolve as a JSON Pointer only as
# per spec

This seems to indicate that the behavior is intentional. However, I can't figure out what spec is being referred to here. I assumed it was Draft 4, but I didn't see anything about this behavior in https://datatracker.ietf.org/doc/html/draft-zyp-json-schema-04 or the corresponding validation spec (https://datatracker.ietf.org/doc/html/draft-fge-json-schema-validation-00). Am I missing something obvious?

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

1 participant