Skip to content

Commit

Permalink
Merge branch 'master' into v8
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Mar 21, 2021
2 parents 1a968ec + 1b07663 commit de1c568
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 90 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ 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/>
<Contributors />

### How we make decisions

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

<script>
import contributors from "./Contributors/_contributors.js";
export default {
data() {
return {
contributors: contributors
}
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);
}
.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>
92 changes: 47 additions & 45 deletions docs/.vuepress/components/RecFeatures.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,65 @@
<p class="text">Choose your JSON schema standard</p>
</div>

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

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

Safety, security and reliability for JavaScript applications

<RecFeatures/>
<RecFeatures />

## Ajv News

Expand Down Expand Up @@ -46,4 +46,4 @@ Try in the playground (TBC)

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

<Contributors/>
<Contributors />
2 changes: 1 addition & 1 deletion docs/json-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ JSON Schema specification defines several metadata keywords that describe the sc
- `title` and `description`: information about the data represented by that schema
- `$comment`: information for developers. With option `$comment` Ajv logs or passes the comment string to the user-supplied function. See [Options](./api.md#options).
- `default`: a default value of the data instance, see [Assigning defaults](#assigning-defaults).
- `default`: a default value of the data instance, see [Assigning defaults](./guide/modifying-data.md#assigning-defaults).
- `examples`: an array of data instances. Ajv does not check the validity of these instances against the schema.
- `readOnly` and `writeOnly`: marks data-instance as read-only or write-only in relation to the source of the data (database, api, etc.).
- `contentEncoding`: [RFC 2045](https://tools.ietf.org/html/rfc2045#section-6.1), e.g., "base64".
Expand Down
9 changes: 4 additions & 5 deletions lib/vocabularies/code.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {AnySchema, SchemaMap} from "../types"
import type {SchemaCxt} from "../compile"
import type {KeywordCxt} from "../compile/validate"
import {CodeGen, _, or, not, nil, strConcat, getProperty, Code, Name} from "../compile/codegen"
import {CodeGen, _, and, or, not, nil, strConcat, getProperty, Code, Name} from "../compile/codegen"
import {alwaysValidSchema, Type} from "../compile/util"
import N from "../compile/names"

Expand All @@ -19,9 +19,8 @@ export function checkMissingProp(
missing: Name
): Code {
return or(
...properties.map(
(prop) =>
_`${noPropertyInData(gen, data, prop, opts.ownProperties)} && (${missing} = ${prop})`
...properties.map((prop) =>
and(noPropertyInData(gen, data, prop, opts.ownProperties), _`${missing} = ${prop}`)
)
)
}
Expand Down Expand Up @@ -60,7 +59,7 @@ export function noPropertyInData(
ownProperties?: boolean
): Code {
const cond = _`${data}${getProperty(property)} === undefined`
return ownProperties ? _`${cond} || !${isOwnProperty(gen, data, property)}` : cond
return ownProperties ? or(cond, not(isOwnProperty(gen, data, property))) : cond
}

export function allSchemaProperties(schemaMap?: SchemaMap): string[] {
Expand Down
4 changes: 2 additions & 2 deletions lib/vocabularies/jtd/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
import type {KeywordCxt} from "../../compile/validate"
import {propertyInData, allSchemaProperties, isOwnProperty} from "../code"
import {alwaysValidSchema, schemaRefOrVal} from "../../compile/util"
import {_, and, Code, Name} from "../../compile/codegen"
import {_, and, not, Code, Name} from "../../compile/codegen"
import {checkMetadata} from "./metadata"
import {checkNullableObject} from "./nullable"
import {typeErrorMessage, typeErrorParams, _JTDTypeError} from "./error"
Expand Down Expand Up @@ -164,7 +164,7 @@ export function validateProperties(cxt: KeywordCxt): void {
if (props.length > 8) {
// TODO maybe an option instead of hard-coded 8?
const propsSchema = schemaRefOrVal(it, parentSchema[keyword], keyword)
additional = isOwnProperty(gen, propsSchema as Code, key)
additional = not(isOwnProperty(gen, propsSchema as Code, key))
} else if (props.length) {
additional = and(...props.map((p) => _`${key} !== ${p}`))
} else {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"types": "dist/ajv.d.ts",
"files": [
"lib/",
"docs/",
"dist/",
"scripts/",
".tonic_example.js"
Expand Down
29 changes: 28 additions & 1 deletion spec/errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ describe("Validation errors", () => {
test(new _Ajv({$data: true}))
test(new _Ajv({$data: true, allErrors: true}))

function test(_ajv) {
function test(_ajv: Ajv) {
const schema = {
type: "object",
required: {$data: "0/req"},
Expand Down Expand Up @@ -347,6 +347,33 @@ describe("Validation errors", () => {
)
}
})

it("should include missing property with ownProperties option (issue #1493)", () => {
test(new _Ajv())
test(new _Ajv({ownProperties: true}))

function test(_ajv: Ajv): void {
const schema = {
type: "object",
required: ["a"],
properties: {
a: {type: "string"},
},
}

const validate = _ajv.compile(schema)
shouldBeValid(validate, {a: "abc"})
shouldBeInvalid(validate, {})
shouldBeError(
validate.errors?.[0],
"required",
"#/required",
"",
"should have required property 'a'",
{missingProperty: "a"}
)
}
})
})

describe('"dependencies" errors', () => {
Expand Down
27 changes: 27 additions & 0 deletions spec/issues/1501_jtd_many_properties.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type Ajv from "../.."
import _Ajv from "../ajv_jtd"
import * as assert from "assert"

const PROP_COUNT = 10

describe("schema with many properties", () => {
let ajv: Ajv
const schema = {properties: {}}
const data = {}
const invalidData = {}

before(() => {
ajv = new _Ajv()
for (let i = 0; i < PROP_COUNT; i++) {
const prop = `prop${i}`
schema.properties[prop] = {type: "uint16"}
data[prop] = i
invalidData[prop] = -i
}
})

it("should correctly compile reference to schema", () => {
assert.strictEqual(ajv.validate(schema, data), true)
assert.strictEqual(ajv.validate(schema, invalidData), false)
})
})

0 comments on commit de1c568

Please sign in to comment.