xeipuuv/gojsonschema

Schemas referenced by id assume type = object

mltsy opened this issue · 2 comments

mltsy commented

I have a schema with a field that is referencing a subschema that is of type string, but the validator is telling me the field using that reference is expected to be an object.

Here is the schema JSON:

{
  "$schema": "http://json-schema.org/schema#",
  "$id": "http://smartersorting.com/test.v1.schema.json",
  "type": "object",
  "properties": {
    "field1": { "$ref": "#ternary_value" }
  },
  "definitions": {
    "ternary_value_schema" : {
      "type" : "string",
      "enum" : ["confirmed", "rejected", "undetermined"],
      "$id": "ternary_value"
    }
  }
}

Here is the test JSON:

{
  "field1": "rejected"
}

Here is the error I get:

field1: Invalid type. Expected: object, given: string

@mltsy The both values of $ref and $id should be the same

"field1": { "$ref": "#ternary_value" }  
"$id": "#ternary_value"
mltsy commented

😮 Wow.

Thank you very much @willson-chen!

Well that's a confusing error message for that error! Should I put in a new issue to output a better error message when a ref is not found?? Or maybe I'll just change the title of this one and update the description 😄