by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 09 17:55
    50kudos commented #1208
  • Jul 06 19:54
    lsirivong commented #867
  • Jul 04 18:44
  • Jul 04 17:37
  • Jul 04 15:51
    Travis ajv-validator/ajv (v6.12.3) passed (2602)
  • Jul 04 15:45

    epoberezkin on v6.12.3

    (compare)

  • Jul 04 15:45

    epoberezkin on master

    6.12.3 (compare)

  • Jul 04 15:38

    epoberezkin on npm_and_yarn

    (compare)

  • Jul 04 15:38

    epoberezkin on master

    Bump mocha from 7.2.0 to 8.0.1 … Merge branch 'master' into depe… Merge pull request #1229 from a… (compare)

  • Jul 04 15:38
    epoberezkin closed #1229
  • Jul 04 15:37

    epoberezkin on npm_and_yarn

    (compare)

  • Jul 04 15:37

    epoberezkin on master

    Bump eslint from 6.8.0 to 7.3.1… Merge branch 'master' into depe… Merge pull request #1234 from a… (compare)

  • Jul 04 15:37
    epoberezkin closed #1234
  • Jul 04 14:44
  • Jul 04 13:37
  • Jul 04 13:10
    Travis ajv-validator/ajv (dependabot/npm_and_yarn/mocha-8.0.1) fixed (2596)
  • Jul 04 13:09
    FloEdelmann commented #867
  • Jul 04 13:09
    FloEdelmann synchronize #867
  • Jul 04 13:07
    Travis ajv-validator/ajv (dependabot/npm_and_yarn/eslint-7.3.1) fixed (2594)
  • Jul 04 13:02
    epoberezkin synchronize #1229
Evgeny Poberezkin
@epoberezkin
@/all any interest to contribute to draft-8 support and generally to Ajv development further?
@Relequestual is there change log - everything that was added/changed/removed?
Ben Hutton
@Relequestual
@epoberezkin You'd have to look at each document. There's a changelog at the end, which is in the index
Mahmoud Abd Al Kareem
@MahmoudAbdAlKareem
Hello
I'm trying to use ajv for FHIR schema validation
IS there any resources for that?
ttxndrx
@ttxndrx
When referencing external schemas with $ref, can the compiled schema provide an expanded/evaluated representation, where all references are replaced by the actual schemas?
Matthew Miller
@mamiller93
Does AJV support openAPI's spec for base64 format? If I do format:'base64', AJV throws an error saying "unknown format "base64" is used in schema at path..."
GaryFNC
@GaryFNC
This might be an old question - I"m new to the full on JSON schema world.. Evgeny has posted issues related to parameterized schemas which is a critical need for my current project. I don't see that resolved - so I didnt know if ajv had experimental support for it - or if there is a standard workaround using some form or pre-processing... Any help/suggestions/pointers would be much appreciated
Kartikey Tanna
@tannakartikey

Hello.
I am not able to do the following:

{
  "$id": "nextDefinition",
  "type": {
    "oneOf": [
      {
        "type": "string"
      },
      {
        "type": "number"
      }
    ]
  }
}

Error:

schema is invalid: data.type should be equal to one of the allowed values, data.type should be array, data.type should match some schema in anyOf

Any idea why can't use oneOf for type?

Kartikey Tanna
@tannakartikey
I got it type should be set to ['number', 'object']. Next challenge is how to validate of it's an object?
Kartikey Tanna
@tannakartikey
Evgeny Poberezkin
@epoberezkin
@GaryFNC parameters was never implemented, turned out to be quite tricky. Only schema generation at this point. The idea obviously was to compile once and use with multiple parameters, not recompile for each parameter.
@mamiller93 you can define custom format for base64
@ttxndrx re resolving refs - see FAQ
FHIR schema - there is a closer issue, FHIR schemas are incorrect but can easily be fixed
Saurav Agrawal
@asaurav025
Hi @epoberezkin I want to validate default value in present in schema against it sub-schema can you suggest some way, I may need to more validations on default data to be checked during compile time
Mohammed Zaghloul
@msalahz
Hi, I posted the following question on StackOverflow, All responses will be appreciated.
https://stackoverflow.com/questions/59919062/can-the-following-json-schema-be-normalized-without-if-then-else-exist-inside-co
Vadorequest
@Vadorequest
Hello! I'm using AJV to check a big settings object, and now I want to add a new property which is a function. But the "function" keyword doesn't work. How can I do that?
      feedback:
        type: object
        properties:
          enabled:
            type: boolean
          saveFeedback: *endpoint
          updateFeedback: *endpoint
          onFeedbackChange: function
        additionalProperties: false
        required:
        - enabled
        - saveFeedback
        - updateFeedback
Prince-1501
@Prince-1501
hello Everyone Please guide me on this. I will stuck at this point
https://stackoverflow.com/questions/56365720/how-to-validate-a-complex-schema-using-meta-schema
Marcin Pucilowski
@Pucilowski
I am building an editor around a JSON document backed by a schema. As part of the flow, a user is allowed to 'focus' on a particular node (indicated by a JSON Pointer) and an editor specific to that document location is generated based on the properties available at this location. Is there a utility to resolve the subset of the schema as indicated by the pointer?
James Gardner
@james-gardner
Hi, I'm wondering if I can grab some help. I'm stuck with a JSONSchema (draft-04) where we have a 'subType' keyword inside certain blocks. subType can be DATETIME, YORN and a few other things. I wanted to write a custom keyword to map these types to things like datetime.
Unfortunately I can't change the schema, it comes from a legacy platform that will explode if I touch it.
Custom keywords seem to be the way to go but I'm not sure about how best to go switching schemas between the different values of 'subType'
Matthias Mohr
@m-mohr
@james-gardner I also have a custom keyword called "subtype" implemented for my use case, maybe it helps: https://github.com/Open-EO/openeo-js-processgraphs/blob/master/src/jsonschema.js#L23 - Not sure whether that's the best way to go (probably not), but it works for me ;-)
James Gardner
@james-gardner
Epic @m-mohr - I reckon this is a good starter. Thank you!!
Evgeny Poberezkin
@epoberezkin
@Pucilowski it’s not possible in general case, but for some subset of schemas there ajv-inspector that tried to do it - I didn’t use it though
Rajiv Mothilal
@rmothilal
Hi @epoberezkin I hope you are well, im new to Ajv and ended up getting here through openapi-backend. I am attempting to validate a schema that has regex that contains unicode properties '^(?!\s$)[\p{L}\p{Nd} .,'-]{1,128}$' so since NodeJS 10 that regex can be passed to RegExp, you would also need to pass in a unicode flag so it would look like 'new RegExp('^(?!\s$)[\p{L}\p{Nd} .,'-]{1,128}$' , 'u')' this issue I am having is that i cannot get the regex to work correctly. it seems to parse correctly when I use escapes eg. ('^(?!\s*$)[\p{L}\p{Nd} .,\'-]{1,128}$') but it doesn't seem to validate properly, i notice that your library accepts a unicode boolean flag. Could this be used to add the unicode flag to where the pattern in the schema gets converted to regex? Please let me know if I am unclear about anything I have said or if you require more info
Thanks in advance
Rajiv Mothilal
@rmothilal
@epoberezkin i noticed if i change line 362 in lib/compile/index.js patternCode function
return 'var pattern' + i + ' = new RegExp(' + util.toQuotedString(patterns[i]) + ',\'u\');';
then it correctly validates my regex, how can we use the configuration to better handle this scenario?
Evgeny Poberezkin
@epoberezkin
I believe the specification assumes basic regular expressions without flags, you can use custom keyword regexp from ajv-keywords - it supports flags (unless I misunderstood what you are trying to achieve)
Rajiv Mothilal
@rmothilal
Hi @epoberezkin thanks for getting back to me, I am using the https://github.com/anttiviljami/openapi-backend library which uses Ajv, I will try to chat to the owner of that library and determine if there is a way that he could implement it in their code
davidmoshal
@davidmoshal

Hi, struggling with something that must be doable, but I can't seem to find the documentation on how to do it.
Given 2 interfaces:

interface MyObject {
    subA: MySubObject;
}
interface MySubObject {
    propA: number;
}

and a schema generated with YousefED/typescript-json-schema:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
        "MySubObject": {
            "properties": {
                "propA": {
                    "type": "number"
                }
            },
            "required": [
                "propA"
            ],
            "type": "object"
        }
    },
    "properties": {
        "subA": {
            "$ref": "#/definitions/MySubObject"
        }
    },
    "required": [
        "subA"
    ],
    "type": "object"
}

Question: how can I validate that this is a valid SubObject:

{
    propA: 10
}
davidmoshal
@davidmoshal

answered my own question:

 ajv.validate("#/definitions/MySubObject", {
       propA: 10
    }
);

Which, BTW, is not in the ajv documentation, as far as I can see.
Works well though!

Cory Mawhorter
@cmawhorter
i finally got around to reading the 2019-09 release notes and that angrily lead me to json-schema-org/json-schema-spec#710 and #1082. @epoberezkin -- have you considered a fork of the spec? for validation, json schema seems to be charging down the wrong path.
Evgeny Poberezkin
@epoberezkin
@cmawhorter there is JTD - see another issue pinned in Ajv repo, and it is likely to become RFC this year. JTD is on the opposite end of the spectrum, focussed on cross-platform type definitions (read - very simple types only), with limited validation capability. There is definitely a place for a middle ground specification, but I do not have capacity to work on it, to be honest.
If Ajv succeeds in raising funds (I started a small campaign) I’ll supervise it to support JSON Schema, JTD and whatever thing in the middle that pops up. I do not want to write the spec myself though.
Cory Mawhorter
@cmawhorter
JTD is interesting and looks to be making rapid progress. here's to hoping that continues. from a quick look, it seems like it will since it leans heavily on another existing standard. if i had to choose between jtd and json schema in terms of what i want/need i'd choose jtd every time. ajv support would send a strong signal for sure.
ajv is great. i'll take a look at sponsoring as soon as i can.
John Grant
@cyrfer
hi all, I am trying to use if/then. The "if" never fails in Ajv, but in other validators it fails as expected.
"ajv": "^6.12.2",
John Grant
@cyrfer
i found my problem. i had if/then inside the properties block.
Nazar Hussain
@nazarhussain
Hi all, Is there a way to extend the behavior of existing keywords? e.g. If we want const to behave differently based on some other schema keyword present?
Evgeny Poberezkin
@epoberezkin
Some of them can be removed and redefined, but not all of them. I would not recommend it though
Ojas Mohril
@ojas1
I'm trying to use ajv with typescript. Here's my problem: I want to access the params.additionalProperty field from tha ErrorObject to be able to print a user-friendly hint to remove the additional property. I get a type error, saying Property 'additionalProperty' is missing in type 'RefParams'. I can see a similar ajv-validator/ajv#843 was raised but I couldn't find the solution there. Can anyone please help?
jamrhein
@jamrhein

N00b question, how can I output an error in the CLI format (keyword, schemaPath,etc.. ) instead of this:
node_modules/ajv/lib/ajv.js:93

if (!v) throw new Error('no schema with key or ref "' + schemaKeyRef + '"');

Error: no schema with key or ref "

Evgeny Poberezkin
@epoberezkin
not sure I understand the context...
4 replies
Evgeny Poberezkin
@epoberezkin
The error in your message above is schema compilation error (incorrect reference), not validation error. If the schema compiles correctly, you will have the same fields in the error object, as in the docs