-
-
Notifications
You must be signed in to change notification settings - Fork 219
Test relative reference resolution when ID is not present #123
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
Test relative reference resolution when ID is not present #123
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, can somebody else review as well? @Relequestual @handrews @Julian
@handrews we both approved it and I merged it, but I think we've done it wrong. The convention in these tests is that the files are available at http://localhost:1234, so subSchemas.json full URI is http://localhost:1234/subSchemas.json. But subschemas.json doesn't have id in it, so there is no base URI. I don't think that the file is available at http://localhost:1234 should make it its base URI if there is no id attribute - I think for this test to be correct id attribute should be added to it. Do you agree? |
And it also broke build. I will revert it. |
Hey @epoberezkin,
That is what I interpreted this part as saying:
The qualifier 'or the empty URI if the schema was not loaded from a URI' seems like it implies the initial 'URI of the schema itself' is the URI it was loaded from if it was loaded from a URI. Maybe I should open an issue at the json-schema-spec repo? |
If we fetch the file from http://localhost:1234/subSchemas.json then per RFC 3986 that is the document's base URI. We should be testing that implementations use the correct base URI in this situation, in which case we cannot include an The "empty URI if the schema was not loaded from a URI" is from the JSON Reference spec which is relevant to Draft 04 but not to later drafts (which don't seem to have that language). In RFC 3986 §5.1 terms, this would be the application-specific default base URI. |
Yep, exactly. My validator passed the test suite but did not set a base URI, so relative references did not work if the schema did not include an |
On another hand, the spec says that ID is schema URI, but ID doesn't mean it can be downloaded there. See #114 (comment) So I am not sure. @Julian's validator failed this test too, that's why I reverted. If we decide that it should work this way as this test required, the validator should be fixed before we can add this test. |
@epoberezkin this is not ambiguous. From RFC 3986 section 5.1:
If there is an id, then we are in the situation marked "(5.1.1) Base URI embedded in content". If we retrieved the JSON Schema document via a URI, then "(5.1.3) URI used to retrieve the entity". The only case where there is anything for the JSON Schema spec to decide is if we did not use a URI to retrieve the document, and there is no URI in the document. @epoberezkin, it doesn't matter whether the document can be fetched at the |
@handrews ok, I have no objection to that. I also thought it should work so I merged it. But then it turned out the validator we have here to test the tests doesn't support it - that was the main reason to revert it, as otherwise we'd lose the ability to test anything else. So if @Julian could implement the support for it we can re-add it. Or we can reduce what Julian's validator tests to draft-03 and test the rest with Ajv (actually not 100% sure if it supports it but I will fix if not). Just let me know how you want to proceed. In any case, having broken tests is not an option I think. |
I haven't been following this issue but if there's something we think that's valid I definitely recommend merging it, we can make the tests pass again even if my library doesn't yet conform. |
It seems clear to me that the library conformance is what is broken, so we should fix that (thanks for supporting this, @Julian ). We should not remove tests because the validator missed a (rather obscure) part of the spec. |
This PR adds a test to ensure that relative references are resolved against the URI of the current schema, as outlined in section 7.1 of the specification and section 4 of the JSON Reference specification.
We currently have the "change resolution scope" test which uses a relative reference, but because the schema has an ID it does not prove that an implementation uses the current schema's URI as the initial resolution scope.