Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Relative $ref pointer not working for files

See original GitHub issue

I have a nodejs application and a folder where all schema reside . The folder are different for both as given below :

Node js application run here – /home/ubuntu/work/node_webhook/webhook.js

Json schema files are stored here :

-- /home/ubuntu/work/analytics/data_types/
------- mobile_schema
------------- test_schema.json
------------- test_2_schema.json
-------- enums.json
-------- common_data_types.json

test_schema.json looks like this :

  "$schema": "",
  "type": "object",
  "properties": {
    "amount": {
      "type": "integer"
    "created_at_date": {
      "$ref": "../common_data_types.json#/common_types/date_time"
    "current_stage": {
       "$ref": "../enum_server.json#/all_enum/CURRENT_STAGE"
  "required": [

common_data_types.json looks like this :

  "$schema": "",
  "type": "object",
  "common_types": {
    "date_time": {
      "type": "string",
      "format": "date-time"

enums.json looks like this

  "$schema": "",
  "all_enum": {
      "type": "string",
      "enum": [
      "type": "string",
      "enum": [

AND NODE JS APLICATION FILE : webhook.js looks like this :

var express = require('express');
var app = express(); 
var $RefParser = require('json-schema-ref-parser');
var Validator = require('jsonschema').Validator;

var v = new Validator();
var parser = new $RefParser();

app.use(bodyParser.urlencoded({ extended: true }));
var router = express.Router();              // get an instance of the express Router

// middleware to use for all requests
router.use(function(req, res, next) {
    console.log('Got a request.');
    next(); // make sure we go to the next routes and don't stop here

function validateEventSchema(req,res){
var event_data =;
var parser = new $RefParser();
var event_schema = parser.bundle("/home/travel/work/trips3m/lib/analytics/data_types/mobile_schema/test_schema.json");

parser.dereference(event_schema, function(err, schema) {
  valid = false;
  if (err) {
  else {
    c = v.validate(event_data, schema);
    if(c.errors.length > 0 ){
      console.log("ERROR OCCUR");
      valid = true ; 


  .post(function(req, res) {

app.use('/', router);

Getting error as it try to resolve ref pointers in current directory in which nodejs application is running . That is : /home/ubuntu/work/node_webhook/ So it cannot find /home/ubuntu/work/node_webhook/enums.json /home/ubuntu/work/node_webhook/common_data_types.json

How will i provide it a base directory to load all json files from . Or how to use relative file path ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

sorohancommented, Jun 30, 2017

@BigstickCarpet. I think according to the schema additional properties should be ignored:

“All other properties in a “$ref” object MUST be ignored.”

In any case, it seems to be breaking the file resolution. If you run with the test I added (npm run mocha) you should see an error:

Error: Error resolving $ref pointer "...json-schema-ref-parser/test/specs/two/id.json".
"...json-schema-ref-parser/test/specs/two/id.json" not found.

And removing the ‘title’ property stops the error.

sul4bhcommented, Apr 28, 2017

@BigstickCarpet I have run into similar issue regarding “$ref” that points to a file location.

My question is, what is the base path for a relative path in $ref? Is the base path relative to where the json file is or is it relative to process.cwd()?

The code that I have right now behaves as if process.cwd() is the base path. Is it the right behavior? Does the spec say anything about it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Relative $ref pointer not working for files #35 - GitHub
I have a nodejs application and a folder where all schema reside . The folder are different for both as given below :...
Read more >
How to use JSON references ($refs) - Redocly
Within a separate file we need a relative path to the file and then the JSON Pointer path to the object separated by...
Read more >
Relative Pointers - gingerBill
Absolute Pointers. Pointers are a value type in programming languages that store a memory address. A pointer references a location in memory ...
Read more >
What is Relative Pointers? - YouTube
Read more >
Excel Formulas: Relative and Absolute Cell References
Relative references change when a formula is copied to another cell. Absolute references, on the other hand, remain constant no matter where they...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found