Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ajv-validator/ajv
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v7.2.1
Choose a base ref
...
head repository: ajv-validator/ajv
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v7.2.2
Choose a head ref

Commits on Mar 7, 2021

  1. Copy the full SHA
    b4aafca View commit details
  2. update readme

    epoberezkin committed Mar 7, 2021
    Copy the full SHA
    3a3c7e1 View commit details
  3. Copy the full SHA
    08669ef View commit details
  4. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    1985d85 View commit details

Commits on Mar 8, 2021

  1. build(deps): bump github action dependencies

    Frazer Smith committed Mar 8, 2021
    Copy the full SHA
    5da0b0d View commit details
  2. docs(readme): correct link

    byr-gdp committed Mar 8, 2021
    Copy the full SHA
    75f8494 View commit details
  3. Merge pull request #1478 from byr-gdp/fix-readme-link

    docs(readme): correct link
    epoberezkin authored Mar 8, 2021
    Copy the full SHA
    b764943 View commit details

Commits on Mar 9, 2021

  1. prepare-site script

    epoberezkin committed Mar 9, 2021
    Copy the full SHA
    578f517 View commit details

Commits on Mar 10, 2021

  1. Copy the full SHA
    6c61fce View commit details
  2. add New home to nav bar

    epoberezkin committed Mar 10, 2021
    Copy the full SHA
    128e608 View commit details
  3. adjust feature rectangles

    spaced4ndy committed Mar 10, 2021
    Copy the full SHA
    d01b45d View commit details

Commits on Mar 11, 2021

  1. [WIP] contributors

    spaced4ndy committed Mar 11, 2021
    Copy the full SHA
    dafba40 View commit details

Commits on Mar 12, 2021

  1. Copy the full SHA
    552c606 View commit details
  2. add contributors html

    spaced4ndy committed Mar 12, 2021
    Copy the full SHA
    7404d21 View commit details
  3. add contributors to README

    spaced4ndy committed Mar 12, 2021
    Copy the full SHA
    336684d View commit details
  4. Copy the full SHA
    7911dc2 View commit details
  5. remove dotenv dependency

    spaced4ndy committed Mar 12, 2021
    Copy the full SHA
    0418f56 View commit details

Commits on Mar 13, 2021

  1. fix style

    spaced4ndy committed Mar 13, 2021
    Copy the full SHA
    8379596 View commit details
  2. Copy the full SHA
    4ff927d View commit details
  3. Copy the full SHA
    1a54158 View commit details
  4. fix tab

    spaced4ndy committed Mar 13, 2021
    Copy the full SHA
    f44d018 View commit details
  5. Copy the full SHA
    0d55baf View commit details
  6. Merge pull request #1482 from ajv-validator/docs-home

    docs: add contributors; rework home (in progress)
    spaced4ndy authored Mar 13, 2021
    Copy the full SHA
    f7dc112 View commit details
  7. CODEOWNERS file

    epoberezkin committed Mar 13, 2021
    Copy the full SHA
    13c97c3 View commit details
  8. simplify some of the JTDSchema

    This is done by better labeling types, and exclusively deciding, ranther
    than forming types as unions with a bunch of nevers
    erikbrinkman committed Mar 13, 2021
    Copy the full SHA
    7e4d919 View commit details
  9. Copy the full SHA
    663ee00 View commit details

Commits on Mar 14, 2021

  1. Fix link for assigning defaults

    Fixes the assigning defaults link, from an anchor tag to the modifying data during validation page
    cbrwflo authored Mar 14, 2021
    Copy the full SHA
    40a175a View commit details
  2. upgrade jimp v0.16.1

    epoberezkin committed Mar 14, 2021
    Copy the full SHA
    5951666 View commit details
  3. $recursiveRef: only skip tests $recursiveRef with no $recursiveAnchor…

    … in the initial target schema resource
    epoberezkin committed Mar 14, 2021
    Copy the full SHA
    6ba56e5 View commit details
  4. simplify with IsRecord

    erikbrinkman committed Mar 14, 2021
    Copy the full SHA
    18f6646 View commit details
  5. remove link from nav

    epoberezkin committed Mar 14, 2021
    Copy the full SHA
    b68d44f View commit details

Commits on Mar 15, 2021

  1. npm beta version

    epoberezkin committed Mar 15, 2021
    Copy the full SHA
    195bb51 View commit details
  2. Copy the full SHA
    596f0c6 View commit details
  3. Merge pull request #1484 from erikbrinkman/simple

    simplify some of the JTDSchema
    epoberezkin authored Mar 15, 2021
    Copy the full SHA
    f7b6098 View commit details
  4. Copy the full SHA
    bf8a4b7 View commit details
  5. Merge pull request #1467 from Fdawgs/build/gh-actions

    build(deps): bump github action dependencies
    epoberezkin authored Mar 15, 2021
    Copy the full SHA
    595b1ca View commit details

Commits on Mar 17, 2021

  1. Copy the full SHA
    119569d View commit details
  2. fix link

    epoberezkin committed Mar 17, 2021
    Copy the full SHA
    f95a6d0 View commit details
  3. Copy the full SHA
    9916514 View commit details
  4. Copy the full SHA
    5ca4629 View commit details

Commits on Mar 18, 2021

  1. Merge pull request #1499 from ajv-validator/format-vue

    chore: format older vue components
    spaced4ndy authored Mar 18, 2021
    Copy the full SHA
    2ada8d6 View commit details

Commits on Mar 19, 2021

  1. Copy the full SHA
    3ae14a3 View commit details
  2. Copy the full SHA
    4f83021 View commit details

Commits on Mar 20, 2021

  1. 7.2.2

    epoberezkin committed Mar 20, 2021
    Copy the full SHA
    678f243 View commit details
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@epoberezkin
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 14
registry-url: https://registry.npmjs.org/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -42,7 +42,9 @@ package-lock.json

spec/_json/*.js

# docs
docs/README.md
docs/code_of_conduct.md
docs/contributing.md
docs/license.md
docs/.vuepress/components/Contributors/
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ permalink: /contributing

Thank you for your help making Ajv better! Every contribution is appreciated. There are many areas where you can contribute.

::: tip Please note
::: tip Submit issue first
If you plan to implement a new feature or some other change please create an issue first, to make sure that your work is not lost.
:::

7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,12 +4,13 @@

# Ajv: Another JSON schema validator

Super fast JSON schema validator for Node.js and browser.
Super fast JSON validator for Node.js and browser.

Supports JSON Schema draft-06/07/2019-09 (draft-04 is supported in [version 6](https://github.com/ajv-validator/ajv/tree/v6)) and JSON Type Definition [RFC8927](https://datatracker.ietf.org/doc/rfc8927/).

[![build](https://github.com/ajv-validator/ajv/workflows/build/badge.svg)](https://github.com/ajv-validator/ajv/actions?query=workflow%3Abuild)
[![npm](https://img.shields.io/npm/v/ajv.svg)](https://www.npmjs.com/package/ajv)
[![npm (beta)](https://img.shields.io/npm/v/ajv/beta)](https://www.npmjs.com/package/ajv)
[![npm downloads](https://img.shields.io/npm/dm/ajv.svg)](https://www.npmjs.com/package/ajv)
[![Coverage Status](https://coveralls.io/repos/github/ajv-validator/ajv/badge.svg?branch=master)](https://coveralls.io/github/ajv-validator/ajv?branch=master)
[![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv)
@@ -54,6 +55,8 @@ At Ajv, we are committed to creating more equitable and inclusive spaces for our

We strive to create an environment of respect and healthy discourse by setting standards for our interactions and we expect it from all members of our community - from long term project member to first time visitor. For more information, review our [code of conduct](./CODE_OF_CONDUCT.md) and values.

<Contributors />

### How we make decisions

We value conscious curation of our library size, and balancing performance and functionality. To that end, we cannot accept every suggestion. When evaluating pull requests we consider:
@@ -242,7 +245,7 @@ const valid = validate(data)
if (!valid) console.log(validate.errors)
```

See more examples in [Guide: getting started](./docs/guide/getting-started)
See more examples in [Guide: getting started](./docs/guide/getting-started.md)

## Extending Ajv

37 changes: 37 additions & 0 deletions docs/.vuepress/components/Contributors.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template>
<div>
<a
v-for="(contributor, i) in contributors"
class="contributor"
:style="'background-position: ' + (100 * i) / (contributors.length - 1) + '% 0'"
:href="'https://github.com/' + contributor"
>
{{ contributor }}
</a>
</div>
</template>

<script>
import contributors from "./Contributors/_contributors.js"
export default {
data() {
return {
contributors: contributors,
}
},
}
</script>

<style scoped>
.contributor {
width: 2.4em;
height: 2.4em;
border-radius: 50%;
text-indent: -9999px;
display: inline-block;
background: no-repeat url(./Contributors/contributors.jpg);
background-size: auto 102%;
margin: 0 0.5em 0.5em 0;
border: 2px solid var(--second);
}
</style>
29 changes: 16 additions & 13 deletions docs/.vuepress/components/GitHub.vue
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
<template>
<ClientOnly>
<span>
<a class="github-button"
<a
class="github-button"
href="https://github.com/ajv-validator/ajv"
data-show-count="true"
data-size="large"
aria-label="Star ajv-validator/ajv on GitHub"
>Star</a>
>
Star
</a>
</span>
</ClientOnly>
</template>

<script>
export default {
mounted() {
let githubScript = document.createElement("script")
githubScript.setAttribute("src", "https://buttons.github.io/buttons.js")
document.head.appendChild(githubScript)
}
}
export default {
mounted() {
let githubScript = document.createElement("script")
githubScript.setAttribute("src", "https://buttons.github.io/buttons.js")
document.head.appendChild(githubScript)
},
}
</script>

<style scoped>
span {
vertical-align: -8px;
padding-left: 20px;
}
span {
vertical-align: -8px;
padding-left: 20px;
}
</style>
79 changes: 79 additions & 0 deletions docs/.vuepress/components/RecFeatures.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<template>
<div>
<div class="rec" id="less-code">
<p class="header">Write less code</p>
<p class="text">Ensure your data is valid once it's received</p>
</div>

<div class="rec" id="fast-and-secure">
<p class="header">Super fast and secure</p>
<p class="text">The fastest and the most secure JSON validator</p>
</div>

<div class="rec" id="multi-spec">
<p class="header">Multi-specification</p>
<p class="text">Choose your JSON schema standard</p>
</div>

<br class="clearBoth" />
</div>
</template>

<style scoped>
.rec {
display: inline-block;
float: left;
margin: 10px;
width: 430px;
height: 300px;
border-radius: 8px;
}
.rec#less-code {
background: #007bff;
}
.rec#fast-and-secure {
background: #00a3aa;
}
.rec#multi-spec {
background: #f5775b;
}
.header {
position: relative;
width: 359px;
height: 39px;
left: 30px;
top: 30px;
font-family: Heebo;
font-style: normal;
font-weight: normal;
font-size: 36px;
line-height: 39px;
color: #ffffff;
}
.text {
position: relative;
width: 359px;
height: 78px;
left: 30px;
top: 30px;
font-family: Heebo;
font-style: normal;
font-weight: normal;
font-size: 24px;
line-height: 39px;
color: #ffffff;
}
.clearBoth {
clear: both;
}
</style>
4 changes: 4 additions & 0 deletions docs/HOME.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

Safety, security and reliability for JavaScript applications

<RecFeatures />

## Ajv News

This section will include the last update and the headlines of several previous updates, e.g. these sections:
@@ -43,3 +45,5 @@ Try in the playground (TBC)
## Contributors

Ajv is free to use and open-source that many developers contributed to. Join us!

<Contributors />
21 changes: 8 additions & 13 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -84,8 +84,8 @@ const serializeMyData = ajv.compileSerializer(mySchema)
// it prevents you from accidentally passing the wrong type
```

::: warning Please note
Compiled serializers do NOT validate passed data, it is assumed that the data is valid according to the schema. In the future there may be an option added that would make serializers also validate the data.
::: warning Compiled serializers do NOT validate data!
It is assumed that the data is valid according to the schema.
:::

<a name="jtd-parse"></a>
@@ -113,10 +113,6 @@ console.log(parseMyData.position) // 4
console.log(parseMyData.message) // property x not allowed
```

::: warning Please note
Generated parsers is a NEW Ajv functionality (as of March 2021), there can be some edge cases that are not handled correctly - please report any issues/submit fixes.
:::

<sup>\*</sup> As long as empty schema `{}` is not used - there is a possibility to improve performance in this case. Also, the performance of parsing `discriminator` schemas depends on the position of discriminator tag in the schema - the best parsing performance will be achieved if the tag is the first property - this is how compiled JTD serializers generate JSON in case of discriminator schemas.

<a name="api-compileAsync"></a>
@@ -147,7 +143,7 @@ Validation errors will be available in the `errors` property of Ajv instance (`n

In typescript this method can act as a type guard (similarly to function returned by `compile` method - see example there).

::: warning Please note
::: warning Save errors property
Every time this method is called the errors are overwritten so you need to copy them to another variable if you want to use them later.
:::

@@ -169,13 +165,12 @@ Although `addSchema` does not compile schemas, explicit compilation is not requi

By default the schema is validated against meta-schema before it is added, and if the schema does not pass validation the exception is thrown. This behaviour is controlled by `validateSchema` option.

::: tip Please note
Ajv return it instance for method chaining from all methods with the prefix `add*` and `remove*`:
::: tip Method chaining
Ajv returns its instance for chaining from all methods prefixed `add*` and `remove*`:

```javascript
const validate = new Ajv().addSchema(schema).addFormat(name, regex).getSchema(uri)
```

:::

### ajv.addMetaSchema(schema: object | object[], key?: string): Ajv
@@ -304,7 +299,7 @@ interface KeywordDefinition {

`compile`, `macro` and `code` are mutually exclusive, only one should be used at a time. `validate` can be used separately or in addition to `compile` or `macro` to support [\$data reference](./guide/combining-schemas.md#data-reference).

::: tip Please note
::: tip Keyword is validated only for applicable data types
If the keyword is validating data type that is different from the type(s) in its definition, the validation function will not be called (and expanded macro will not be used), so there is no need to check for data type inside validation function or inside schema returned by macro function (unless you want to enforce a specific type and for some reason do not want to use a separate `type` keyword for that). In the same way as standard keywords work, if the keyword does not apply to the data type being validated, the validation of this keyword will succeed.
:::

@@ -320,7 +315,7 @@ Removes added or pre-defined keyword so you can redefine them.

While this method can be used to extend pre-defined keywords, it can also be used to completely change their meaning - it may lead to unexpected results.

::: warning Please note
::: warning Compiled schemas and removed keywords
The schemas compiled before the keyword is removed will continue to work without changes. To recompile schemas use `removeSchema` method and compile them again.
:::

@@ -367,7 +362,7 @@ interface JTDErrorObject {

This error format is used when using JTD schemas. To simplify usage, you may still generate Ajv error objects using `ajvErrors` option. You can also add a human-readable error message to error objects using option `messages`.

::: warning Please note
::: warning JTD errors are not fully spec-compliant
Ajv is not fully consistent with JTD regarding the error objects in some scenarios - it will be consistent by the time Ajv version 8 is released. Therefore it is not recommended yet to use error objects for any advanced application logic.
:::

4 changes: 2 additions & 2 deletions docs/codegen.md
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ CodeGen class generates code trees and performs several optimizations before the
2. removes unused variable declarations.
3. replaces variables that are used only once and assigned expressions that are explicitly marked as "constant" (i.e. having referential transparency) with the expressions themselves.

::: warning Please note
::: warning Optimizations assume no side effects
These optimizations assume that the expressions in `if` conditions, `for` statement headers and assigned expressions are free of any side effects - this is the case for all pre-defined validation keywords.
:::

@@ -87,6 +87,6 @@ While tagged template literals wrap passed strings based on their run-time value

It is strongly recommended to define additional keywords only with Typescript - using plain JavaScript would still allow passing unsafe strings to code generation methods.

::: warning Please note
::: warning Optimization and side-effects
If your user-defined keywords need to have side-effects that are removed by optimization (see above), you may need to disable it.
:::
2 changes: 1 addition & 1 deletion docs/guide/async-validation.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ You can define formats and keywords that perform validation asynchronously by ac

If your schema uses asynchronous formats/keywords or refers to some schema that contains them it should have `"$async": true` keyword so that Ajv can compile it correctly. If asynchronous format/keyword or reference to asynchronous schema is used in the schema without `$async` keyword Ajv will throw an exception during schema compilation.

::: warning Please note
::: warning Use $async: true in referenced schemas
All asynchronous subschemas that are referenced from the current or other schemas should have `"$async": true` keyword as well, otherwise the schema compilation will fail.
:::

5 changes: 2 additions & 3 deletions docs/guide/combining-schemas.md
Original file line number Diff line number Diff line change
@@ -43,16 +43,15 @@ const validate = ajv.addSchema(defsSchema).compile(schema)

See [Options](./api.md#options) and [addSchema](./api.md#add-schema) method.

::: tip Please note

::: tip Reference resolution
- `$ref` is resolved as the uri-reference using schema \$id as the base URI (see the example).
- References can be recursive (and mutually recursive) to implement the schemas for different data structures (such as linked lists, trees, graphs, etc.).
- You don't have to host your schema files at the URIs that you use as schema \$id. These URIs are only used to identify the schemas, and according to JSON Schema specification validators should not expect to be able to download the schemas from these URIs.
- The actual location of the schema file in the file system is not used.
- You can pass the identifier of the schema as the second parameter of `addSchema` method or as a property name in `schemas` option. This identifier can be used instead of (or in addition to) schema \$id.
- You cannot have the same \$id (or the schema identifier) used for more than one schema - the exception will be thrown.
- You can implement dynamic resolution of the referenced schemas using `compileAsync` method. In this way you can store schemas in any system (files, web, database, etc.) and reference them without explicitly adding to Ajv instance. See [Asynchronous schema compilation](./managing-schemas.md#asynchronous-schema-compilation).
:::
:::

## Extending recursive schemas

2 changes: 1 addition & 1 deletion docs/guide/environments.md
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ This bundle can be used with different module systems; it creates global `ajv`/`

The browser bundles are available on [cdnjs](https://cdnjs.com/libraries/ajv).

::: warning Please note
::: warning Some frameworks re-define require
Some frameworks, e.g. Dojo, may redefine global require in a way that is not compatible with CommonJS module format. In this case Ajv bundle has to be loaded before the framework and then you can use global `ajv` (see issue [#234](https://github.com/ajv-validator/ajv/issues/234)).
:::

Loading