Skip to content

Commit d387b2a

Browse files
authored
Revision 0.33.9 (#984)
* Generate Interior Intersect Errors * Version * ChangeLog
1 parent ed4c89a commit d387b2a

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

changelog/0.33.0.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### 0.33.0
2-
2+
- [Revision 0.33.9](https://github.com/sinclairzx81/typebox/pull/984)
3+
- [887](https://github.com/sinclairzx81/typebox/issues/887) Generate Nested Intersect Errors
34
- [Revision 0.33.8](https://github.com/sinclairzx81/typebox/pull/983)
45
- [982](https://github.com/sinclairzx81/typebox/issues/982) Prevent Intersect Transform Encode callback from being called twice
56
- [974](https://github.com/sinclairzx81/typebox/issues/974) Make strict the Encode and Decode return type

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sinclair/typebox",
3-
"version": "0.33.8",
3+
"version": "0.33.9",
44
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
55
"keywords": [
66
"typescript",

src/errors/errors.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,16 @@ function* FromInteger(schema: TInteger, references: TSchema[], path: string, val
312312
}
313313
}
314314
function* FromIntersect(schema: TIntersect, references: TSchema[], path: string, value: any): IterableIterator<ValueError> {
315+
let hasError = false
315316
for (const inner of schema.allOf) {
316-
const next = Visit(inner, references, path, value).next()
317-
if (!next.done) {
318-
yield Create(ValueErrorType.Intersect, schema, path, value)
319-
yield next.value
317+
for (const error of Visit(inner, references, path, value)) {
318+
hasError = true
319+
yield error
320320
}
321321
}
322+
if (hasError) {
323+
return yield Create(ValueErrorType.Intersect, schema, path, value)
324+
}
322325
if (schema.unevaluatedProperties === false) {
323326
const keyCheck = new RegExp(KeyOfPattern(schema))
324327
for (const valueKey of Object.getOwnPropertyNames(value)) {

test/runtime/errors/types/intersect.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,46 @@ import { Resolve } from './resolve'
44
import { Assert } from '../../assert'
55

66
describe('errors/type/Intersect', () => {
7-
const T = Type.Intersect([Type.Object({ x: Type.Number() }), Type.Object({ y: Type.Number() })])
87
it('Should pass 0', () => {
8+
const T = Type.Intersect([Type.Object({ x: Type.Number() }), Type.Object({ y: Type.Number() })])
99
const R = Resolve(T, { x: 1, y: 1 })
1010
Assert.IsEqual(R.length, 0)
1111
})
1212
it('Should pass 1', () => {
13+
const T = Type.Intersect([Type.Object({ x: Type.Number() }), Type.Object({ y: Type.Number() })])
1314
const R = Resolve(T, { x: 1 })
14-
Assert.IsEqual(R.length, 2)
15-
Assert.IsEqual(R[0].type, ValueErrorType.Intersect)
16-
Assert.IsEqual(R[1].type, ValueErrorType.ObjectRequiredProperty)
15+
Assert.IsEqual(R.length, 3)
16+
Assert.IsEqual(R[0].type, ValueErrorType.ObjectRequiredProperty)
17+
Assert.IsEqual(R[1].type, ValueErrorType.Number)
18+
Assert.IsEqual(R[2].type, ValueErrorType.Intersect)
1719
})
1820
it('Should pass 2', () => {
21+
const T = Type.Intersect([Type.Object({ x: Type.Number() }), Type.Object({ y: Type.Number() })])
1922
const R = Resolve(T, { y: 1 })
20-
Assert.IsEqual(R.length, 2)
21-
Assert.IsEqual(R[0].type, ValueErrorType.Intersect)
22-
Assert.IsEqual(R[1].type, ValueErrorType.ObjectRequiredProperty)
23+
Assert.IsEqual(R.length, 3)
24+
Assert.IsEqual(R[0].type, ValueErrorType.ObjectRequiredProperty)
25+
Assert.IsEqual(R[1].type, ValueErrorType.Number)
26+
Assert.IsEqual(R[2].type, ValueErrorType.Intersect)
27+
})
28+
// ----------------------------------------------------------------
29+
// https://github.com/sinclairzx81/typebox/issues/887
30+
// ----------------------------------------------------------------
31+
it('Should pass 3', () => {
32+
const A = Type.Intersect([Type.Object({ x: Type.Number() }), Type.Object({ y: Type.Number() })])
33+
const B = Type.Intersect([Type.Object({ x: Type.Number() }), Type.Object({ z: Type.Number() })])
34+
const T = Type.Intersect([A, B])
35+
const R = Resolve(T, {})
36+
Assert.IsEqual(R.length, 11)
37+
Assert.IsEqual(R[0].type, ValueErrorType.ObjectRequiredProperty)
38+
Assert.IsEqual(R[1].type, ValueErrorType.Number)
39+
Assert.IsEqual(R[2].type, ValueErrorType.ObjectRequiredProperty)
40+
Assert.IsEqual(R[3].type, ValueErrorType.Number)
41+
Assert.IsEqual(R[4].type, ValueErrorType.Intersect)
42+
Assert.IsEqual(R[5].type, ValueErrorType.ObjectRequiredProperty)
43+
Assert.IsEqual(R[6].type, ValueErrorType.Number)
44+
Assert.IsEqual(R[7].type, ValueErrorType.ObjectRequiredProperty)
45+
Assert.IsEqual(R[8].type, ValueErrorType.Number)
46+
Assert.IsEqual(R[9].type, ValueErrorType.Intersect)
47+
Assert.IsEqual(R[10].type, ValueErrorType.Intersect)
2348
})
2449
})

0 commit comments

Comments
 (0)