Skip to content

Commit 3c34e7f

Browse files
committed
fix to work with Ajv2019 class, rewrite "transform" keyword
1 parent 9a239f8 commit 3c34e7f

File tree

13 files changed

+49
-43
lines changed

13 files changed

+49
-43
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const ajv = new Ajv({
106106
})
107107
```
108108

109-
`opts` is an object with a property `defaultMeta` - URI of meta-schema to use for keywords that use subschemas (`select` and `deepProperties`).
109+
`opts` is an optional object with a property `defaultMeta` - URI of meta-schema to use for keywords that use subschemas (`select` and `deepProperties`). The default is `"http://json-schema.org/schema"`.
110110

111111
## Keywords
112112

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
"homepage": "https://github.com/epoberezkin/ajv-keywords#readme",
3737
"peerDependencies": {
38-
"ajv": "^7.0.0-beta.3"
38+
"ajv": "^7.0.0-beta.6"
3939
},
4040
"devDependencies": {
4141
"@ajv-validator/config": "^0.2.3",
@@ -44,7 +44,7 @@
4444
"@types/uuid": "^8.3.0",
4545
"@typescript-eslint/eslint-plugin": "^4.4.1",
4646
"@typescript-eslint/parser": "^4.4.1",
47-
"ajv": "^7.0.0-beta.3",
47+
"ajv": "^7.0.0-beta.6",
4848
"ajv-formats": "^0.3.4",
4949
"chai": "^4.2.0",
5050
"dot": "^1.1.1",

spec/schema-tests.spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Ajv from "ajv"
1+
import Ajv from "ajv/dist/2019"
22
import type {Vocabulary} from "ajv"
33
import ajvKeywordsPlugin from "../dist"
44
import ajvKeywords from "../dist/definitions"
@@ -16,8 +16,8 @@ const ajvs = [
1616
"deepRequired",
1717
"select",
1818
]),
19-
// ajvKeywordsPlugin(getAjv()),
20-
// ajvKeywordsPlugin(getAjv(true)),
19+
ajvKeywordsPlugin(getAjv()),
20+
ajvKeywordsPlugin(getAjv(true)),
2121
getAjv(undefined, ajvKeywords()),
2222
getAjv(true, ajvKeywords()),
2323
// ajvKeywordsPlugin(getAjvNoMeta()),
@@ -49,7 +49,6 @@ jsonSchemaTest(ajvs, {
4949
function getAjv(extras?: boolean, keywords?: Vocabulary): Ajv {
5050
return new Ajv({
5151
$data: true,
52-
unevaluated: true,
5352
allErrors: extras,
5453
verbose: extras,
5554
keywords,
@@ -62,7 +61,6 @@ function getAjv(extras?: boolean, keywords?: Vocabulary): Ajv {
6261
function getAjvNoMeta(keywords?: Vocabulary): Ajv {
6362
return new Ajv({
6463
$data: true,
65-
unevaluated: true,
6664
keywords,
6765
formats: {allowedUnknown: true},
6866
meta: false,

spec/transform.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ describe('keyword "transform"', () => {
100100
try {
101101
ajv.validate(schema, data).should.equal(false)
102102
} catch (e) {
103-
e.message.should.equal(
104-
'Missing enum. To use `transform:["toEnumCase"]`, `enum:[...]` is required.'
105-
)
103+
e.message.should.match(/transform.*enum/)
106104
}
107105

108106
data = ["ph"]
@@ -113,9 +111,7 @@ describe('keyword "transform"', () => {
113111
try {
114112
ajv.validate(schema, data).should.equal(false)
115113
} catch (e) {
116-
e.message.should.equal(
117-
'Invalid enum uniqueness. To use `transform:["toEnumCase"]`, all values must be unique when case insensitive.'
118-
)
114+
e.message.should.match(/transform.*unique/)
119115
}
120116

121117
data = [" ph "]

src/definitions/_util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type {DefinitionOptions} from "./_types"
22
import type {SchemaObject, CodeGen, Name} from "ajv"
3-
import {_} from "ajv/dist/compile/codegen"
3+
import {_} from "ajv"
44

5-
const META_SCHEMA_ID = "http://json-schema.org/draft-07/schema"
5+
const META_SCHEMA_ID = "http://json-schema.org/schema"
66

77
export function metaSchemaRef({defaultMeta}: DefinitionOptions = {}): SchemaObject {
88
return defaultMeta === false ? {} : {$ref: defaultMeta || META_SCHEMA_ID}

src/definitions/deepRequired.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ export default function getDef(): CodeKeywordDefinition {
3131
function unescapeJPSegment(s: string): string {
3232
return s.replace(/~1/g, "/").replace(/~0/g, "~")
3333
}
34+
35+
module.exports = getDef

src/definitions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ const definitions: GetDefinition<KeywordDefinition>[] = [
3838
export default function ajvKeywords(opts?: DefinitionOptions): Vocabulary {
3939
return definitions.map((d) => d(opts)).concat(selectDef(opts))
4040
}
41+
module.exports = ajvKeywords

src/definitions/patternRequired.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ export default function getDef(): CodeKeywordDefinition {
4040
},
4141
}
4242
}
43+
44+
module.exports = getDef

src/definitions/regexp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {CodeKeywordDefinition, KeywordCxt, JSONSchemaType, Name} from "ajv"
2-
import {_} from "ajv/dist/compile/codegen"
2+
import {_} from "ajv"
33
import {usePattern} from "./_util"
44

55
interface RegexpSchema {

src/definitions/select.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {KeywordDefinition, KeywordErrorDefinition, KeywordCxt} from "ajv"
2-
import {_, str, nil, Name} from "ajv/dist/compile/codegen"
2+
import {_, str, nil, Name} from "ajv"
33
import type {DefinitionOptions} from "./_types"
44
import {metaSchemaRef} from "./_util"
55

@@ -63,3 +63,5 @@ export default function getDef(opts?: DefinitionOptions): KeywordDefinition[] {
6363
},
6464
]
6565
}
66+
67+
module.exports = getDef

0 commit comments

Comments
 (0)