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 and $ref in same properties object #271

Closed
mbwhite opened this issue Feb 1, 2019 · 4 comments
Closed

Use of $id and $ref in same properties object #271

mbwhite opened this issue Feb 1, 2019 · 4 comments

Comments

@mbwhite
Copy link

mbwhite commented Feb 1, 2019

Hello - this might be related to #270 but I think it's subtly different.

I've reduced the schema I was using to

{
    "$schema": "http://json-schema.org/draft-07/schema",
    "type": "object",
    "title": "",
    "definitions": {
        "objecttype": {
            "description": "A complex type used in a domain",
            "type": "object",
            "properties": {
                "$id": {
                    "type": "string"
                },
                "required": {
                    "$ref": "http://json-schema.org/draft-07/schema#/definitions/stringArray"
                }
            }
        }
    },
    "properties":{
        "schemas": {
            "$ref": "#/definitions/objecttype"
        }
    }
}

Using this code to load it

        try (InputStream inputStream = getClass().getResourceAsStream("testschema.json")) {
            JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));

            SchemaLoader loader = SchemaLoader.builder().draftV7Support().schemaJson(rawSchema).build();
            Schema schema = loader.load().build();

            System.out.println(schema);

        }

This generates a SchemaException:

org.everit.json.schema.SchemaException: #/definitions/objecttype/properties/%24id: expected type: String, found: JsonObject
        at org.everit.json.schema.loader.LoadingState.createSchemaException(LoadingState.java:155)
        at org.everit.json.schema.loader.JsonValue.requireString(JsonValue.java:186)
        at org.everit.json.schema.loader.JsonValue.requireString(JsonValue.java:179)
        at org.everit.json.schema.loader.ReferenceLookup.lookupObjById(ReferenceLookup.java:94)
        at org.everit.json.schema.loader.ReferenceLookup.lookupObjById(ReferenceLookup.java:99)
        at org.everit.json.schema.loader.ReferenceLookup.lookupObjById(ReferenceLookup.java:99)
        at org.everit.json.schema.loader.ReferenceLookup.lookupObjById(ReferenceLookup.java:99)
        at org.everit.json.schema.loader.ReferenceLookup.lookup(ReferenceLookup.java:142)
        at org.everit.json.schema.loader.ReferenceSchemaExtractor.extract(SchemaExtractor.java:163)
        at org.everit.json.schema.loader.AbstractSchemaExtractor.extract(SchemaExtractor.java:80)
        at org.everit.json.schema.loader.SchemaLoader.runSchemaExtractors(SchemaLoader.java:342)
        at org.everit.json.schema.loader.SchemaLoader.loadSchemaObject(SchemaLoader.java:323)
        at org.everit.json.schema.loader.JsonValue$Multiplexer.requireAny(JsonValue.java:44)
        at org.everit.json.schema.loader.SchemaLoader.load(SchemaLoader.java:393)

Tried on other schemas - ajv specifically - and this is accepted.

Thoughts welcome.

@erosb
Copy link
Contributor

erosb commented Feb 2, 2019

Hello,

thanks for reporting the bug. This is now fixed in the master branch, you can use it immediately by setting dd455601549b65c748577568cb4494f7e5ac2d69 as the dependency version in your pom.xml (JitPack will handle it), or wait until the next release.

@erosb erosb closed this as completed Feb 2, 2019
erosb added a commit that referenced this issue Feb 2, 2019
erosb added a commit that referenced this issue Feb 2, 2019
@mbwhite
Copy link
Author

mbwhite commented Feb 4, 2019

@erosb that's great - appreciate the speedy fix.

For info - how often does a release occur?

@erosb
Copy link
Contributor

erosb commented Feb 4, 2019

Usually 1-2 months, and the last one was released 2 weeks ago, so if it is urgent I recommend using the commit hash.

@erosb
Copy link
Contributor

erosb commented Mar 17, 2019

The fix is released in version 1.11.1.

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

2 participants