8000 build(deps-dev): bump eslint from 7.32.0 to 8.35.0 by dependabot[bot] · Pull Request #111 · ronyhe/ajv · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

build(deps-dev): bump eslint from 7.32.0 to 8.35.0 #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export interface CurrentOptions {
loadSchema?: (uri: string) => Promise<AnySchemaObject>
// options to modify validated data:
removeAdditional?: boolean | "all" | "failing"
removeUnevaluated?: boolean
useDefaults?: boolean | "empty"
coerceTypes?: boolean | "array"
// advanced options:
Expand Down
6 changes: 5 additions & 1 deletion lib/vocabularies/unevaluated/unevaluatedProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const def: CodeKeywordDefinition = {
const {gen, schema, data, errsCount, it} = cxt
/* istanbul ignore if */
if (!errsCount) throw new Error("ajv implementation error")
const {allErrors, props} = it
const {allErrors, props, opts} = it
if (props instanceof Name) {
gen.if(_`${props} !== true`, () =>
gen.forIn("key", data, (key: Name) =>
Expand Down Expand Up @@ -66,6 +66,10 @@ const def: CodeKeywordDefinition = {
)
if (!allErrors) gen.if(not(valid), () => gen.break())
}

if (opts.removeUnevaluated) {
gen.code(_`delete ${data}[${key}]`)
}
}

function unevaluatedDynamic(evaluatedProps: Name, key: Name): Code {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"prettier:write": "prettier --write \"./**/*.{json,yaml,js,ts}\"",
"prettier:check": "prettier --list-different \"./**/*.{json,yaml,js,ts}\"",
"test-spec": "cross-env TS_NODE_PROJECT=spec/tsconfig.json mocha -r ts-node/register \"spec/**/*.spec.{ts,js}\" -R dot",
"myTest": "cross-env TS_NODE_PROJECT=spec/tsconfig.json mocha -r ts-node/register \"spec/options/removeUnevaluated.spec.ts\"",
"test-codegen": "nyc cross-env TS_NODE_PROJECT=spec/tsconfig.json mocha -r ts-node/register 'spec/codegen.spec.ts' -R spec",
"test-debug": "npm run test-spec -- --inspect-brk",
"test-cov": "nyc npm run test-spec",
Expand Down Expand Up @@ -81,7 +82,7 @@
"cross-env": "^7.0.2",
"dayjs": "^1.10.4",
"dayjs-plugin-utc": "^0.1.2",
"eslint": "^7.8.1",
"eslint": "^8.35.0",
"eslint-config-prettier": "^7.0.0",
"fast-uri": "^1.0.0",
"glob": "^7.0.0",
Expand Down
134 changes: 134 additions & 0 deletions spec/options/removeUnevaluated.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import _Ajv from "../ajv2019"
import chai from "../chai"
chai.should()

describe("removeAdditional option", () => {
it("should remove unevaluated properties", () => {
const ajv = new _Ajv({removeUnevaluated: true, unevaluated: true})

ajv.addSchema({
$id: "//test/fooBar",
type: "object",
properties: {foo: {type: "string"}, bar: {type: "string"}},
unevaluatedProperties: true,
})

const object = {
foo: "foo",
bar: "bar",
baz: "baz-to-be-removed",
}

ajv.validate("//test/fooBar", object).should.equal(true)
object.should.have.property("foo")
object.should.have.property("bar")
object.should.not.have.property("baz")
})

it("should remove redundant properties in oneOf situations", () => {
const ajv = new _Ajv({removeUnevaluated: true, unevaluated: true})
ajv.addSchema({
$id: "//test/fooBar",
type: "object",
oneOf: [
{
required: ["a", "b"],
properties: {
a: {type: "number"},
b: {type: "number"},
},
},
{
properties: {
c: {type: "number"},
d: {type: "number"},
},
},
],
unevaluatedProperties: true,
})
const object = {
b: 2,
c: 3,
d: 4,
}
ajv.validate("//test/fooBar", object).should.equal(true)
object.should.not.have.property("b")
object.should.have.property("c")
object.should.have.property("d")
})

it("should remove redundant properties in anyOf situations, for the first alternative", () => {
const ajv = new _Ajv({removeUnevaluated: true, unevaluated: true})
ajv.addSchema({
$id: "//test/fooBar",
type: "object",
anyOf: [
{
required: ["a", "b"],
properties: {
a: {type: "number"},
b: {type: "number"},
},
unevaluatedProperties: true
},
{
required: ["c", "d"],
properties: {
c: {type: "number"},
d: {type: "number"},
},
},
],
unevaluatedProperties: true,
})
const object = {
a: 1,
b: 2,
c: 3,
d: 4,
}
ajv.validate("//test/fooBar", object).should.equal(true)
object.should.have.property("a")
object.should.have.property("b")
object.should.not.have.property("c")
object.should.not.have.property("d")
})

it("should remove redundant properties in anyOf situations, for subsequent alternatives", () => {
const ajv = new _Ajv({removeUnevaluated: true, unevaluated: true})
ajv.addSchema({
$id: "//test/fooBar",
type: "object",
anyOf: [
{
required: ["a", "b"],
properties: {
a: {type: "number"},
b: {type: "number"},
},
unevaluatedProperties: true
},
{
required: ["c", "d"],
properties: {
c: {type: "number"},
d: {type: "number"},
},
},
],
unevaluatedProperties: true,
})
const object = {
b: 2,
c: 3,
d: 4,
}
ajv.validate("//test/fooBar", object).should.equal(true)
object.should.not.have.property("a")
object.should.not.have.property("b")
object.should.have.property("c")
object.should.have.property("d")
})

})
0