-
-
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
* Add failing test for integer subschema narrowing * Add number to includesType check for context types * narrow number to integer correctly * fix lint errors Co-authored-by: Jacob Ley <jacob@getshowcase.io>
- Loading branch information
1 parent
a211e8d
commit a489265
Showing
2 changed files
with
121 additions
and
1 deletion.
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,111 @@ | ||
import _Ajv from "../ajv" | ||
import Ajv from "ajv" | ||
import * as assert from "assert" | ||
|
||
describe("integer valid type in number sub-schema (issue #1935)", () => { | ||
let ajv: Ajv | ||
before(() => { | ||
ajv = new _Ajv({strict: true}) | ||
}) | ||
|
||
it("should allow integer in `if`", () => | ||
assert.doesNotThrow(() => | ||
ajv.compile({ | ||
type: "number", | ||
if: { | ||
type: "integer", | ||
maximum: 5, | ||
}, | ||
else: { | ||
minimum: 10, | ||
}, | ||
}) | ||
)) | ||
|
||
it("should allow integer in `then`", () => | ||
assert.doesNotThrow(() => | ||
ajv.compile({ | ||
type: "number", | ||
if: { | ||
multipleOf: 2, | ||
}, | ||
then: { | ||
type: "integer", | ||
minimum: 10, | ||
}, | ||
}) | ||
)) | ||
|
||
it("should allow integer in `else`", () => | ||
assert.doesNotThrow(() => | ||
ajv.compile({ | ||
type: "number", | ||
if: { | ||
maximum: 5, | ||
}, | ||
else: { | ||
type: "integer", | ||
minimum: 10, | ||
}, | ||
}) | ||
)) | ||
|
||
it("should allow integer in `allOf`", () => | ||
assert.doesNotThrow(() => | ||
ajv.compile({ | ||
type: "number", | ||
allOf: [ | ||
{ | ||
type: "integer", | ||
minimum: 10, | ||
}, | ||
{ | ||
multipleOf: 2, | ||
}, | ||
], | ||
}) | ||
)) | ||
|
||
it("should allow integer in `oneOf`", () => | ||
assert.doesNotThrow(() => | ||
ajv.compile({ | ||
type: "number", | ||
oneOf: [ | ||
{ | ||
type: "integer", | ||
minimum: 10, | ||
}, | ||
{ | ||
multipleOf: 2, | ||
}, | ||
], | ||
}) | ||
)) | ||
|
||
it("should allow integer in `anyOf`", () => | ||
assert.doesNotThrow(() => | ||
ajv.compile({ | ||
type: "number", | ||
oneOf: [ | ||
{ | ||
type: "integer", | ||
minimum: 10, | ||
}, | ||
{ | ||
multipleOf: 2, | ||
}, | ||
], | ||
}) | ||
)) | ||
|
||
it("should allow integer in `not`", () => | ||
assert.doesNotThrow(() => | ||
ajv.compile({ | ||
type: "number", | ||
not: { | ||
type: "integer", | ||
minimum: 10, | ||
}, | ||
}) | ||
)) | ||
}) |