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

meta-schemas cannot be loaded asynchronously #334

Closed
pressureDrop opened this issue Nov 3, 2016 · 3 comments
Closed

meta-schemas cannot be loaded asynchronously #334

pressureDrop opened this issue Nov 3, 2016 · 3 comments

Comments

@pressureDrop
Copy link

What version of Ajv are you using? Does the issue happen if you use the latest version?

ajv - 4.8.2

Ajv options object (see https://github.com/epoberezkin/ajv#options):

{
    loadSchema: function(uri, callback) {
        request(uri, function(err, res, body) {
          if (err || res.statusCode >= 400)
            callback(err || new Error('Loading error: ' + res.statusCode));
          else
            callback(null, JSON.parse(body));
        });
    }
}

JSON Schema (please make it as small as possible to reproduce the issue):

{
    "$schema": "http://json-schema.org/draft-04/hyper-schema#",
    "properties": {
        "links": {
            "type": "array",
            "items": {
                "$ref": "http://json-schema.org/draft-04/hyper-schema#/definitions/linkDescription"
            }
        }
    }
}

Data (please make it as small as posssible to reproduce the issue):

{"links":[{"rel":"foo","href":"/foo"}]}

Your code (please use options, schema and data as variables):

var request = require("request");
var Ajv = require('ajv');
var ajv = Ajv({
    loadSchema: function(uri, callback) {
        request(uri, function(err, res, body) {
          if (err || res.statusCode >= 400)
            callback(err || new Error('Loading error: ' + res.statusCode));
          else
            callback(null, JSON.parse(body));
        });
    }
});

var schema = {
    "$schema": "http://json-schema.org/draft-04/hyper-schema#",
    "properties": {
        "links": {
            "type": "array",
            "items": {
                "$ref": "http://json-schema.org/draft-04/hyper-schema#/definitions/linkDescription"
            }
        }
    }
};

ajv.compileAsync(schema, function(error, validate) {
  if (error) {
    console.log(error);
  } else {
    console.log('valid:', validate({"links":[{"rel":"foo","href":"/foo"}]}));
  };
});

https://runkit.com/lwhitaker/581b813da447b8001345f61f

I get this result:

Error: no schema with key or ref "http://json-schema.org/draft-04/hyper-schema#"

What results did you expect?

I expected the schema to be resolved.

Are you going to resolve the issue?

Sounds like you already have a fix for this coming in 5.0.

@epoberezkin
Copy link
Member

@pressureDrop there is no fix yet, let me know if you want to make a PR to 5.0.0 branch.

@epoberezkin
Copy link
Member

epoberezkin commented Nov 8, 2016

TODO:

  • docs
  • dts

@epoberezkin
Copy link
Member

epoberezkin commented Nov 8, 2016

In 5.0.0-beta.0.
To use: npm install ajv@^5.0.0-beta

@epoberezkin epoberezkin modified the milestone: 5.0.0 Nov 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants