Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 18:05
    evilstiefel commented #1101
  • 17:19
    afwn90cj93201nixr2e1re commented #1100
  • 17:19
    afwn90cj93201nixr2e1re commented #1100
  • 17:06
    evilebottnawi commented #1100
  • 16:56
    afwn90cj93201nixr2e1re commented #1100
  • 16:55
    afwn90cj93201nixr2e1re commented #1100
  • 16:05
    epoberezkin closed #1101
  • 16:05
    epoberezkin commented #1101
  • 14:16
    evilstiefel commented #1101
  • 14:07
    evilstiefel commented #1101
  • 14:07
    evilstiefel commented #1101
  • 13:56
    epoberezkin commented #137
  • 13:32
    epoberezkin commented #137
  • 13:31
    muhabalwan commented #137
  • 13:28
    muhabalwan commented #137
  • 13:28
    muhabalwan commented #137
  • 13:28
    muhabalwan commented #137
  • 13:19
    epoberezkin commented #1101
  • 13:14
    evilstiefel edited #1101
  • 13:13
    evilstiefel labeled #1101
Evgeny Poberezkin
@epoberezkin
@B-Teague this weekend :)
Brian Teague
@B-Teague
@epoberezkin I’m working on a pull request for ajv-keywords to allow dynamicDefaults to work with the new “empty” option. I’ve got the coding changes done, just working on the chai test cases.
Brian Teague
@B-Teague

@epoberezkin Okay, I am running into possibly two problems. 1) My code change is not mutating the data
'''
return it.opts.useDefaults && !it.compositeRule
? assignDefaults
: noop;

  function assignDefaults(data) {
    for (var prop in schema){
      if (data[prop] === undefined
        || it.opts.useDefaults == 'empty'
        && (data[prop] === null || data[prop] === ''))
        data[prop] = funcs[prop]();
    }
    return true;
  }

'''
2) Is the data being compared to the type and format before the default logic can execute?

Brian Teague
@B-Teague
@epoberezkin Okay, so my code change does actually work, but only when the schema does not have type integer or a format present.
Do I need to open an issue against ajv or ajv-keywords to execute the default logic before checking format and type?
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? =]