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: v8.6.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: v8.6.2
Choose a head ref
  • 7 commits
  • 7 files changed
  • 5 contributors

Commits on Jul 4, 2021

  1. Copy the full SHA
    001f829 View commit details

Commits on Jul 15, 2021

  1. Copy the full SHA
    71a29b8 View commit details
  2. build(deps-dev): bump husky from 6.0.0 to 7.0.1 (#1678)

    Bumps [husky](https://github.com/typicode/husky) from 6.0.0 to 7.0.1.
    - [Release notes](https://github.com/typicode/husky/releases)
    - [Commits](typicode/husky@v6.0.0...v7.0.1)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    
    Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
    dependabot-preview[bot] authored Jul 15, 2021
    Copy the full SHA
    c22894a View commit details
  3. build(deps-dev): bump @types/node from 15.14.2 to 16.3.2 (#1689)

    Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 15.14.2 to 16.3.2.
    - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
    - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)
    
    Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
    
    Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
    dependabot-preview[bot] authored Jul 15, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    18de168 View commit details
  4. Copy the full SHA
    ceac236 View commit details
  5. WIP error change (#1674)

    franrolando authored Jul 15, 2021
    Copy the full SHA
    426fe51 View commit details
  6. 8.6.2

    epoberezkin committed Jul 15, 2021
    Copy the full SHA
    a046570 View commit details
Showing with 33 additions and 21 deletions.
  1. +7 −7 .github/workflows/build.yml
  2. +1 −1 docs/guide/user-keywords.md
  3. +8 −8 docs/json-schema.md
  4. +1 −1 lib/compile/errors.ts
  5. +1 −1 lib/compile/jtd/serialize.ts
  6. +3 −3 package.json
  7. +12 −0 spec/jtd-timestamps.spec.ts
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -22,13 +22,13 @@ jobs:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: git submodule update --init
- name: update website
if: ${{ github.event_name == 'push' && matrix.node-version == '14.x' }}
run: ./scripts/publish-site
env:
GH_TOKEN_PUBLIC: ${{ secrets.GH_TOKEN_PUBLIC }}
GIT_USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
GIT_USER_NAME: ${{ secrets.GIT_USER_NAME }}
# - name: update website
# if: ${{ github.event_name == 'push' && matrix.node-version == '14.x' }}
# run: ./scripts/publish-site
# env:
# GH_TOKEN_PUBLIC: ${{ secrets.GH_TOKEN_PUBLIC }}
# GIT_USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
# GIT_USER_NAME: ${{ secrets.GIT_USER_NAME }}
- run: npm run build
- run: npm run test-ci
- name: coveralls
2 changes: 1 addition & 1 deletion docs/guide/user-keywords.md
Original file line number Diff line number Diff line change
@@ -56,4 +56,4 @@ console.log(validate(4)) // false

Several keywords (typeof, instanceof, range and propertyNames) are defined in [ajv-keywords](https://github.com/ajv-validator/ajv-keywords) package - they can be used for your schemas and as a starting point for your own keywords.

See [User-defined keywords](./keywords.md) reference for more details.
See [User-defined keywords](../keywords.md) reference for more details.
16 changes: 8 additions & 8 deletions docs/json-schema.md
Original file line number Diff line number Diff line change
@@ -453,16 +453,16 @@ For the data array to be valid, the items with indices less than the number of s

_schema_:

```javascript
{
type: "array",
prefixItems: [{type: "integer"}, {type: "string"}]
}
```
```javascript
{
type: "array",
prefixItems: [{type: "integer"}, {type: "string"}]
}
```

_valid_: `[1]`, `[1, "abc"]`, `[1, "abc", 2]`, `[]`
_valid_: `[1]`, `[1, "abc"]`, `[1, "abc", 2]`, `[]`

_invalid_: `["abc", 1]`, `["abc"]`
_invalid_: `["abc", 1]`, `["abc"]`

The schema in example will log warning by default (see `strictTuples` option), because it defines unconstrained tuple. To define a tuple with exactly 2 elements use [minItems](#minitems) and [items](#items-in-draft-2020-12) keywords (see example 2 in [items](#items-in-draft-2020-12)).

2 changes: 1 addition & 1 deletion lib/compile/errors.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import {getErrorPath, Type} from "./util"
import N from "./names"

export const keywordError: KeywordErrorDefinition = {
message: ({keyword}) => str`should pass "${keyword}" keyword validation`,
message: ({keyword}) => str`must pass "${keyword}" keyword validation`,
}

export const keyword$DataError: KeywordErrorDefinition = {
2 changes: 1 addition & 1 deletion lib/compile/jtd/serialize.ts
Original file line number Diff line number Diff line change
@@ -213,7 +213,7 @@ function serializeType(cxt: SerializeCxt): void {
case "timestamp":
gen.if(
_`${data} instanceof Date`,
() => gen.add(N.json, _`${data}.toISOString()`),
() => gen.add(N.json, _`'"' + ${data}.toISOString() + '"'`),
() => serializeString(cxt)
)
break
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ajv",
"version": "8.6.1",
"version": "8.6.2",
"description": "Another JSON Schema Validator",
"main": "dist/ajv.js",
"types": "dist/ajv.d.ts",
@@ -70,7 +70,7 @@
"@rollup/plugin-typescript": "^8.2.1",
"@types/chai": "^4.2.12",
"@types/mocha": "^8.0.3",
"@types/node": "^15.0.2",
"@types/node": "^16.3.2",
"@types/require-from-string": "^1.2.0",
"@typescript-eslint/eslint-plugin": "^3.8.0",
"@typescript-eslint/parser": "^3.8.0",
@@ -83,7 +83,7 @@
"eslint": "^7.8.1",
"eslint-config-prettier": "^7.0.0",
"glob": "^7.0.0",
"husky": "^6.0.0",
"husky": "^7.0.1",
"if-node-version": "^1.0.0",
"jimp": "^0.16.1",
"js-beautify": "^1.7.3",
12 changes: 12 additions & 0 deletions spec/jtd-timestamps.spec.ts
Original file line number Diff line number Diff line change
@@ -67,4 +67,16 @@ describe("JTD timestamps", function () {
assert.strictEqual(parseTS('"2021-05-14"')?.toISOString(), "2021-05-14T00:00:00.000Z")
})
})

describe("serializing Date objects", () => {
it("should serialize Date as JSON string", () => {
const schema: JTDSchemaType<Date> = {type: "timestamp"}
const ajv = new _AjvJTD()
const serializeTS = ajv.compileSerializer(schema)
assert.strictEqual(
serializeTS(new Date("2021-05-14T17:59:03.851Z")),
'"2021-05-14T17:59:03.851Z"'
)
})
})
})