java-json-tools / json-schema-validator

A JSON Schema validation implementation in pure Java, which aims for correctness and performance, in that order
http://json-schema-validator.herokuapp.com/
Other
1.63k stars 400 forks source link

URI "commonsMixed.json#" is not absolute #125

Open javadev686 opened 10 years ago

javadev686 commented 10 years ago

-------------sampleJosnSchema.json--------------- { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "AccountUpdateRequest": { "$ref": "commonsMixed.json#/definitions/d_Locales" } } }

------------------commonsMixed.json---------------------- { "definitions": { "d_NonZeroLengthString": { "description": "Non Zero Length String", "type": "string", "minLength": 1 }, "d_Locales": { "$ref": "#/definitions/d_NonZeroLengthString", "enum": [ "en", "es" ] } } }

---------------sampleJson.json--------- { "AccountUpdateRequest": "es" }

------used maven dependecy-----

com.github.fge json-schema-validator 2.2.6

on validating sampleJson.json with sampleJosnSchema.json i am getting below error com.github.fge.jsonschema.core.exceptions.ProcessingException: fatal: URI "commonsMixed.json#" is not absolute

Note : sampleJosnSchema.json and commonsMixed.json are at same location for example desktop

I found similar issue reported in https://github.com/fge/json-schema-validator/issues/94 but how can some one expect to put hard coded path in json schema. i believe there must be some other work around atleast.

can some one please help me.

tripti-singh commented 9 years ago

I am facing same issue. Any resolution?

bruceflowers commented 7 years ago

Bump

tadhgpearson commented 7 years ago

Also seeing the same issue :(

tadhgpearson commented 7 years ago

Aha - there's a good workaround. In your target schema, you need to add an id property that documents the path to the file. So, in the above example, you would modify commonsMixed.json to contain its own relative path to the file, within a folder on your class path like so

{
  "$schema" : "http://json-schema.org/draft-04/schema" ,
  "id": "resource:/path/within/your/maven/resources/folder/commonsMixed.json#",
  "definitions": {
     ... ( properties go here)
  }
}

If you've got a maven project (like me) this is the path to the schema file within your src/main/resources folder.

It's a bit annoying but it will get you through. Hope that helps!