Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 17 23:45
    epoberezkin commented #1392
  • Jan 17 23:45
    epoberezkin commented #1392
  • Jan 17 23:44
    epoberezkin commented #1392
  • Jan 17 23:39
    epoberezkin commented #1392
  • Jan 17 23:39
    epoberezkin labeled #1395
  • Jan 17 23:39
    epoberezkin unlabeled #1395
  • Jan 17 23:39
    epoberezkin commented #1395
  • Jan 17 23:37
    epoberezkin commented #1346
  • Jan 17 03:51
    Travis WilliamHeaven/ajv (test_karma) still failing (94)
  • Jan 16 18:41
    bricejar commented #1346
  • Jan 16 18:38
    G-Rath commented #1392
  • Jan 16 18:27
    bricejar commented #1346
  • Jan 16 17:29
    bricejar commented #1346
  • Jan 16 17:26
    bricejar commented #1394
  • Jan 16 17:09
    tidhar-ziv commented #1387
  • Jan 16 16:50
    lmk07 labeled #1395
  • Jan 16 16:50
    lmk07 opened #1395
  • Jan 16 16:49
    lmk07 commented #1392
  • Jan 16 14:30
    epoberezkin labeled #1394
  • Jan 16 14:30
    epoberezkin commented #1394
Evgeny Poberezkin
@epoberezkin
The problem can be missing “required” or missing “type”
Property name is misspelled - you are not prohibiting additional properties
So it is not validated
Dimitris Karittevlis
@safinn

Hello, im testing ajv v7 beta 3 and with this schema

social: {
      $id: '#/properties/social',
      type: 'array',
      default: [],
      additionalItems: true,
      items: {
        $id: '#/properties/social/items',
        anyOf: [
          {
            $id: '#/properties/social/items/anyOf/0',
            type: 'string',
            default: '',
          },
        ],
      },
    },

it fails with Error: strict mode: "additionalItems" without "items" is ignored
Not sure if its a schema error or not. additionalItems and items are both defined.

Evgeny Poberezkin
@epoberezkin
additionalItems is ignored unless items is an array of schemas
See strict mode
In this schema additionalItems does nothing, and Ajv no longer allows ignored keywords by default (you can disable@strict mode though)
the error message needs to be clarified - I was just trying to keep them short
so if you remove additionalItems it will work
Dimitris Karittevlis
@safinn
Thanks for responding. I think im misunderstanding the additionalItems
rule. Does it allow multiple schemas and when false it only allow the individual schema?
Evgeny Poberezkin
@epoberezkin
See the examples in docs/JSON-schema.md
Dimitris Karittevlis
@safinn
and because i only have 1 scheme i can move it outside anyof
Evgeny Poberezkin
@epoberezkin
No
Dimitris Karittevlis
@safinn
without anyof it will not validate all items in the array?
Evgeny Poberezkin
@epoberezkin
AdditionalItems is only needed if you have a schema for n-tuple - items keyword having an array of schemas
As is it will validate all items with or without additionalItems, so you can just remove it
Dimitris Karittevlis
@safinn
great thank you for clarifying!
Evgeny Poberezkin
@epoberezkin
anyOf also does nothing in your case, but it’s not related to the error. Ajv should optimise it away in complied code but it’s better to remove it too (unless you need multiple branches of course)
Dimitris Karittevlis
@safinn
Ill remove it :D
social: {
      $id: '#/properties/social',
      type: 'array',
      default: [],
      items: {
        $id: '#/properties/social/items',
        type: 'string',
        minLength: 3,
      },
    },
Justin Calleja
@justin-calleja
@epoberezkin thank you! It was a typo ^^; and setting additionalProperties is a pretty good idea :)
Evgeny Poberezkin
@epoberezkin
Yes - I’ve seen it ;)
JSON Schema is a very permissive spec, v7 has strict mode by default though, so it’s more difficult to make some silly and hard to find errors like typos etc.
Mir Rayees
@RayeesMir
is it possible to validate if one property is less than another property?
SilentEsper
@SilentEsper

Greetings!
I'm making use of AVJ in my application and I'm pleased with the API so far, I'm reaching out because I was unable to find in the documentation directions to validate a specific definition in a schema,

I'm working with a large schema of about 88 definitions, and I'd like to validate against each one independently.
If I missed this part of the documentation kindly direct me there!
Many thanks for this great library!

Evgeny Poberezkin
@epoberezkin
That’s JSON Schema spec, not Ajv specific - it would definitely help reviewing the spec itself
You can ajv.getSchema(“schema#/definitions/name”) - to get validation function for a definition (where “schema” is schema URI in its $id)
What docs may benefit from is “recipes”, as API is documented but many of its application are not obvious
cbc-ott-dev
@cbc-ott-dev
Hey @epoberezkin, great work :-) I'm using your project everywhere and for a long time without knowing it ;-). I currently writing a Docker container to do a lot of OpenAPI tooling out-of-the-box (linting, resolving, sdk-generation, docs-generation, mock-server, testing) each with a simple CLI command.
Unfortunately my tests fail because of this: ajv-validator/ajv#1119
To give me a kick-start: Which files do you think I have to edit/touch in your project to solve that Issue, so that my upcoming PR gets accepted?
Evgeny Poberezkin
@epoberezkin
@cbc-ott-dev have a look at the file I recently added: docs/components.md - it should help with some pointers. I've actually looked at this issue, it would have been a valuable addition to v7 - happy to guide the implementation plan. Please comment on the issue once you review how you think it should be done, but it's definitely easier in v7 that in was in v6
@/all in case you missed the spam from all the failed builds ;) - Ajv v7 is now the main latest version and other packages are updated too - ajv-keywords, ajv-errors and ajv-cli
R.T
@RatchapongT
const Ajv = require('ajv').default;
const ajv = new Ajv();
const validate = ajv.compile({
  additionalItems: { type: 'boolean' },
  items: [
    { type: 'string' },
    { type: 'number' },
  ],
  minItems: 3,
  type: 'array',
});
console.log(validate(['a', 3, true, false]))  // expect true
console.log(validate(['a', 3]))  // expect false
console.log(validate(['a', 3, '3'])) // expect false
This works perfectly but it is screaming strict mode: "items" is 2-tuple, but minItems or maxItems/additionalItems are not specified or different
How can i make the schema work like this without loging the strict mode?
I know we can turn off the log via option, but I want to have correct and clean schema that is also strict.
Evgeny Poberezkin
@epoberezkin
There is an option strictTuples: false that would allow such arrays without disabling the rest of the strict mode
Adam
@adamfortuno
What's the JSON schema draft 7 syntax to indicate that a property is required only if another property is present. Both properties are in different objects contained in the same object.
Adam
@adamfortuno
You people are no help :-)
Evgeny Poberezkin
@epoberezkin
:)
No such syntax in JSON Schema
There are dependencies keyword but they are for siblings
Actually you can use if/then in the common parent and put extra layers of “properties” in both if and then to get to the properties you need
Seems like good SO question ;)
0x0DD1DEA5
@0x0DD1DEA5
Hello, I wanted to ask why AJV is relying on dynamic functions for validation.
Are there some technical limitations that forced you to do it this way or maybe some performance reasons?
Evgeny Poberezkin
@epoberezkin
By dynamic you mean compile schema to JS vs interpreting it? If so - it’s indeed performance - compiling makes validation itself 50-200 times faster depending on the schema and implementation
Compilation itself is slower of course, it only makes sense if you compile once / validate many times - e.g. server side or form validation on every key press
0x0DD1DEA5
@0x0DD1DEA5
Yes indeed, this is what I mean, I'm asking because I'm using a ui-generator that depends on AJV and since in my company there are very strict secure policies I cannot change CSP. So I was wondering if I'll be able to get around it somehow
Anyway, ty
Evgeny Poberezkin
@epoberezkin
You can use standalone code and generate it during the build
Assuming schema is fixed and you can move compilation to build
See standalone.md
0x0DD1DEA5
@0x0DD1DEA5
Yeah I know, but that's the issue, it has to be all done with configuration