Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 12 20:53
    afwn90cj93201nixr2e1re commented #1100
  • Oct 11 16:49
    evilebottnawi labeled #1100
  • Oct 11 16:49
    evilebottnawi opened #1100
  • Oct 10 23:34

    greenkeeper[bot] on coveralls-3.0.7

    (compare)

  • Oct 10 23:19
    Travis epoberezkin/ajv@770b493 (greenkeeper/coveralls-3.0.7) passed (2362)
  • Oct 10 23:14

    greenkeeper[bot] on coveralls-3.0.7

    chore(package): update coverall… (compare)

  • Oct 10 22:24
    FloEdelmann synchronize #867
  • Oct 08 18:04
    epoberezkin labeled #1099
  • Oct 08 18:04
    epoberezkin unlabeled #1099
  • Oct 08 18:04
    epoberezkin locked #1099
  • Oct 08 18:04
    epoberezkin closed #1099
  • Oct 08 18:04
    epoberezkin commented #1099
  • Oct 08 15:21
    julien-f labeled #1099
  • Oct 08 15:21
    julien-f opened #1099
  • Oct 08 08:08

    greenkeeper[bot] on uglify-js-3.6.1

    (compare)

  • Oct 08 08:08
    Travis epoberezkin/ajv@1163d8c (greenkeeper/uglify-js-3.6.1) passed (2360)
  • Oct 08 08:04

    greenkeeper[bot] on uglify-js-3.6.1

    chore(package): update uglify-j… (compare)

  • Oct 06 23:42
    fabiospampinato edited #1098
  • Oct 06 23:42
    fabiospampinato edited #1098
  • Oct 06 23:42
    fabiospampinato edited #1098
Evgeny Poberezkin
@epoberezkin
It’s processed after validation, unlike default - it’s in the docs. You can control the order with allOf.
After all standard keywords
Brian Teague
@B-Teague
Yup, I see it in the dynamicDefaults section, but totally forgot about it. To make sure I understand, is this schema what you mean?
{
{
type: 'object',
dynamicDefaults: {
r: 'randomint'
},
properties: {
r: { allOf[
type: 'integer',
minimum: 0,
maximum: 100,
exclusiveMaximum: true
]}
}
}
Evgeny Poberezkin
@epoberezkin
I mean that dynamicDefaults can be in the first subschema inside allOf and all validation keywords in the second (properties and type in your case). The syntax above is not clear - allOf needs array of schemas.
As is it validate properties before dynamicDefaults
Brian Teague
@B-Teague
Pull request has been submitted.
Fabre Lambeau
@wabiloo
Hi, quick question - it looks like you have the most complete JSON schema validator for JS - I'm trying to not only validate JSON payloads, but also "decorate" them during validation with information extracted from the schema (eg. Title, comments and extra proprietary information). Could your lib be used for that? I was hoping for some form of hook/callback when a payload property/object successfully matches the schema
Brian Teague
@B-Teague
Hello @wabiloo, can you “decorate” your json using the useDefaults: true option?
Brian Teague
@B-Teague
Example: const schema = { “type”: “object”, “properties”: { “someKey”: { “type”: “string” }, “Title”: { “type”: “string”, “default”: “Your Title” } }; const data = { “someKey”: “someValue” }; console.log(ajv.compile(schema).validate(data));
Evgeny Poberezkin
@epoberezkin
There are custom keywords - they are essentially logic hooks that allow to define arbitrary validation and data manipulation logic - please review the docs.
@wabiloo ^^
Brian Teague
@B-Teague
@epoberezkin Evgeny, when you have a free moment, can you please review and approve my pull request in the ajv-keywords repo? Sorry to keep bothering you!
Fabre Lambeau
@wabiloo
@epoberezkin thanks, I found that and started looking at it. However is there an support for Regexes in the keywords? Otherwise I'd have to hard keywords for every single element of my (rather large) schema
Brian Teague
@B-Teague
Can you provide a before / after json example?
Brian Teague
@B-Teague
Yes, there is already a regexp keyword in the ajv-keywords repo for a given input pattern.
Brian Teague
@B-Teague
@epoberezkin Sorry to bug you again. Just wanted to
Let you know I added a commit that fixed your requested changes
Evgeny Poberezkin
@epoberezkin
Thanks - I’ve seen - will merge/release this week :h
Thanks for helping support it by the way
Brian Teague
@B-Teague
Thank you!! (This is my first pull request to the open source community)
Brian Teague
@B-Teague
@epoberezkin Question: How big of a design change would it be to have all keywords execute before any validation takes place? Since custom keywords have the option to mutate the JSON data, would it be better to execute all custom keywords before validating the mutated JSON against the provided schema? While using the "allOf" compound keyword does work, it feels like an unnecessary hack.
Brian Teague
@B-Teague
Nevermind, I realized you may want to mutate the data after validation using keywords as well. Not sure if there is a way to say run this keyword before validation and run this keyword after validation.
Evgeny Poberezkin
@epoberezkin
I thought a lot about controlling execution order outside of the schema and decided against it for several reasons:
  1. In JSON Schema spec the order is irrelevant and the results never depend on it
  1. For spec extensions that depend on the order it’s clearer when it is explicitly defined by the schema rather than by some options
So with allOf you can have any order with any keywords and it’s always visible from the schema, hiding it in option would lead to the same schema producing different results
Brian Teague
@B-Teague
Yes, I definitely prefer using explicit design. Thanks for adding my pull request!
Vaibhav Mehta
@i-break-codes
Hi, I am trying to validate the meta schema via compile, where I've deliberately made a typo like "type": 'string' and when I do ajv.errorsText(), it returns me data.properties['foo'].type should be equal to one of the allowed values, data.properties['foo'].type should be array, data.properties['foo'].type should match some schema in anyOf .... is there any way to return a simple message that the data type you provided is incorrect?
Evgeny Poberezkin
@epoberezkin
Schema is validated as if it were data against meta schema
Given that normally such errors should be caught by tests, they are rare. making these error messages semantic would affect runtime performance
There may be a value in a separate package for better schema validation and assessment, e.g. from performance and security points of view
Vaibhav Mehta
@i-break-codes

yea, cuz in the current state, it's difficult to show the end-user that what exactly went wrong.. in the above, a simple error message like...

data type for the type attribute is incorrect.

this should help, so any plans for having a separate package in place?

Evgeny Poberezkin
@epoberezkin
Nope
There is ajv-errors
Vaibhav Mehta
@i-break-codes
yea, I checked that but it's for custom error messages only.. anyways, thanks for the quick response.. appreciated
Rui Silva
@RuiAlias
Hi! I have a question but first of all, thanks for ajv! Is there a way to get the complete list of properties of a Schema, with $ref and allOf expanded using ajv?
From what I've read in the FAQ, it looks like this is not possible. If that is the case, can you guys recommend some other library for this?
Rui Silva
@RuiAlias
Thanks!
Ntropy
@Ntropy
Hi,
Is it possible to enable some additional logging, diagnostic messages in ajv?
Evgeny Poberezkin
@epoberezkin
What is the objective?
Ben Hutton
@Relequestual
I'm trying to get validation errors. Is there any sense of validation error bubbling upwards? As in, if I do allOf > [{required: a}], I get the error on the required but not the allOf, and I'd like to see both. Anyone know? =]
Matthias Mohr
@m-mohr

Hey all,
is there a way to interfere the validation of each value before it is validated against the (sub-)schema? Potentially as plugin?

Background:
I have a JSON structure that can hold variables, which we defined to be an object with an id and a type, for example: {variable_id: 'password', type: 'string'}. These can be embedded in my JSON files, for example:

{
  process: 'login',
  arguments: {
    username: 'john_doe',
    password: {variable_id: 'password', type: 'string'}
  }
}

In the end the variable for password is replaced with a string value, but I don't know that value yet. So what I'd like to do here is to interfere at the point where the value of password is checked against the schema. Currently it fails of course, because the variable object is not a string, which is expected in the JSON schema. So what I need to do is to check if there's an object with a variable_id property before validating against the original part of the JSON schema. If there's a variable I need to run a custom function that checks whether the variable definition is compatible to the schema (I have code for that) and if it's not a variable, just run the validation as usual. Where do I need to interfere in the ajv code? Any hints on that? I can't change the JSON schemas, these are coming from an external source.

Thanks in advance...

Ntropy
@Ntropy
@epoberezkin to make possible to handle successed subschemas
Evgeny Poberezkin
@epoberezkin
@Relequestual let me know if allErrors option helps?
@m-mohr please check the custom keywords - that’s what they are for I think