-
-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…2171, fixes #2181 (#2190) * fixes #2001 fixes #2001 * reduce diff * prettier * JTD only optional properties test * Test case * simplify, avoid run time code changes when possible * fix test * style * style * prettier Co-authored-by: Anton Piliugin <87300344+piliugin-anton@users.noreply.github.com> Co-authored-by: Anton Piliugin <anton.piliugin@icloud.com>
- Loading branch information
1 parent
35034b6
commit 5c72864
Showing
2 changed files
with
44 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import _Ajv from "../ajv_jtd" | ||
import * as assert from "assert" | ||
|
||
describe("schema with optional/additional properties only", () => { | ||
const ajv = new _Ajv() | ||
|
||
it("should correctly serialize optional properties", () => { | ||
const schema = { | ||
optionalProperties: { | ||
prop0: {type: "uint16"}, | ||
prop1: {type: "uint16"}, | ||
prop2: {type: "uint16"}, | ||
}, | ||
additionalProperties: true, | ||
} | ||
const serialize = ajv.compileSerializer(schema) | ||
const test = (data, json) => assert.strictEqual(serialize(data), json) | ||
test({prop0: 0, prop1: 1, prop2: 2}, '{"prop0":0,"prop1":1,"prop2":2}') | ||
test({prop1: 1, prop2: 2}, '{"prop1":1,"prop2":2}') | ||
test({prop0: 0, prop1: 1, prop2: 2, foo: "bar"}, '{"prop0":0,"prop1":1,"prop2":2,"foo":"bar"}') | ||
test({prop1: 1, prop2: 2, foo: "bar"}, '{"prop1":1,"prop2":2,"foo":"bar"}') | ||
test({foo: "bar"}, '{"foo":"bar"}') | ||
}) | ||
}) |