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

Use of $id in $ref is not working #321

Closed
sunilgunisetty opened this issue Aug 2, 2019 · 4 comments
Closed

Use of $id in $ref is not working #321

sunilgunisetty opened this issue Aug 2, 2019 · 4 comments

Comments

@sunilgunisetty
Copy link

I have the following schema in 2 different files.

// ProductDescription.json
{
    "$schema" : "http://json-schema.org/draft-07/schema",
    "$id": "https://some-host.com/ProductDescription.json",
    "type": "object",
    "properties": {.
                   "uuid": {
                       "description": "The internal UUID uniquely identifying this entity",
                       "allOf": [
                           { "$ref": "/Types.json#uuid" }
                        ]
                    },    
       }
}

and

//Types.json
{
    "$schema" : "http://json-schema.org/draft-07/schema",
    "$id": "https://some-host.com/types.json",
    "definitions": {
        "uuid": {
            "$id": "#uuid",
            "type": "string",
            "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
        }
    }
}

When I try to load ProductDescription.json I get exception with a message a JSON pointer should start with '/' or '#/' .

I am using static load method in SchemaLoader class to load the schema.

In my front end I use ajv with the same files and it works without any issue.

Am I missing something / am I using wrong methods. Any suggestions is highly appreciated.

@erosb
Copy link
Contributor

erosb commented Aug 13, 2019

Hello @sunilgunisetty , for now I suggest using the { "$ref": "/Types.json#/definitions/uuid" } syntax, ie. referring to the subschema via a json pointer instead of its id.

I re-read the current version of the spec and I think what you ask for should work (though previous json schema drafts explained it differently). But it isn't covered by the official test suite, so I'm not 100% sure. Let's keep this issue open as a feature request.

@sunilgunisetty
Copy link
Author

@erosb Thank you.

@eraserhd
Copy link

I think this says it should work? https://json-schema.org/latest/json-schema-core.html#rfc.section.8.2.4

erosb added a commit that referenced this issue Sep 20, 2019
 * added integ test for reproducing the problem
 * test update: `JsonPointerEvaluatorTest#JsonPointerEvaluatorTest()` now expects the source URI to be set as location for remote fetched documents
    - updating `JsonPointerEvaluator#configureBasedOnState()` to pass the test
 * for reference schemas, using the location of the found object (instead of the resolved URI) as schema location
 * changing `JsonPointerEvaluator#query()` to first try to lookup the result schema by $id in the containing document, before trying to
    use it as a json pointer
 * adding some missing `final` modifiers to fields
@erosb
Copy link
Contributor

erosb commented Sep 20, 2019

This is now fixed and released in version 1.12.0.

@erosb erosb closed this as completed Sep 20, 2019
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