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

doesn't work when $ref has an id #107

Closed
andreineculau opened this issue Jul 29, 2017 · 4 comments
Closed

doesn't work when $ref has an id #107

andreineculau opened this issue Jul 29, 2017 · 4 comments
Assignees
Labels

Comments

@andreineculau
Copy link

andreineculau commented Jul 29, 2017

this should work

{
  "id": "foo",
  "type": "object",
  "properties": {
    "foo": {
      "$ref": "foo"
    }
  },
  "additionalProperties": false
}

but it doesn't - json-schema-to-typescript will try to read a file called "foo", despite having a reference to a schema with id "foo"

@andreineculau
Copy link
Author

apparently this is a lingering issue APIDevTools/json-schema-ref-parser#22 (comment)

@bcherny
Copy link
Owner

bcherny commented Jul 29, 2017

Hi @andreineculau. That is not a valid usage of $ref. What you want is:

{
  "id": "foo",
  "type": "object",
  "properties": {
    "foo": {
      "$ref": "#"
    }
  },
  "additionalProperties": false
}

The issue is unrelated to the one you linked, and is simply how the JSONPointer and JSONSchema specs define $refs. If a $ref doesn't begin with #, it indicates a pointer to an external file (rather than a pointer to somewhere else in the current schema). See the ref.abc tests here, and see sections 8-9 in the JSONSchema spec here.

@bcherny bcherny closed this as completed Jul 29, 2017
@bcherny bcherny self-assigned this Jul 29, 2017
@andreineculau
Copy link
Author

Well, fwiw that was not the case for JSON Schema v4, and that's what I have specified in my local schema's $schema value (missing from the example in this issue).

https://tools.ietf.org/html/draft-zyp-json-schema-04#section-7.2.3

@bcherny
Copy link
Owner

bcherny commented Jul 29, 2017

Read more carefully:

Implementations MUST support canonical dereferencing, and MAY support inline dereferencing.

Don't rely on inline dereferencing.

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

No branches or pull requests

2 participants