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

Throw exception if $schema is present and it is not a string #394

Closed
tizmagik opened this issue Jan 14, 2017 · 3 comments
Closed

Throw exception if $schema is present and it is not a string #394

tizmagik opened this issue Jan 14, 2017 · 3 comments

Comments

@tizmagik
Copy link

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

Latest

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

{}

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

{
  "thing": {
    "type": 123,
  },
}

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

n/a

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

const Ajv = require('ajv');
const ajv = new Ajv();

const isValid = ajv.validateSchema({
  thing: {
    type: 123,
  },
});

console.log(isValid); // true ??

Validation result, data AFTER validation, error messages:

none

What results did you expect?
returns false

Are you going to resolve the issue?
I'd be happy to, unless the issue is I'm doing something wrong (likely)

@epoberezkin
Copy link
Member

thing is "an additional property" in the schema and the specification allows additional properties to be present. It's only if the value of defined keyword were invalid, schema validation would fail, e.g. minimum: false instead of a number.

Usually you don't have to explicitly validate schemas - they are validated when they are added to Ajv instance (unless you disable it).

@tizmagik
Copy link
Author

@epoberezkin I can't re-open but here's the edge-case that I brought up on Gitter. Let me know if you'd like me to open a new issue or if you can edit the original description here.

const Ajv = require('ajv');
const ajv = new Ajv();

const isValid = ajv.validateSchema({
  $schema: {
    thing: {
      type: 'asdf',
    },
  },
});

console.log(isValid); // true ??

@epoberezkin epoberezkin reopened this Jan 14, 2017
@epoberezkin epoberezkin changed the title How to properly use validateSchema() ? Throw exception if $schema is present and it is not a string Jan 15, 2017
@epoberezkin epoberezkin added this to the 5.0.0 milestone Jan 23, 2017
@epoberezkin
Copy link
Member

in 5.0.1-beta.3

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