Skip to content

Commit c07b08f

Browse files
author
jquense
committedApr 14, 2023
fix(object): excluded edges are merged when concating schema
fixes #1969
1 parent f999497 commit c07b08f

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ import { mixed, InferType } from 'yup';
12471247
let objectIdSchema = yup
12481248
.mixed((input): input is ObjectId => input instanceof ObjectId)
12491249
.transform((value: any, input, ctx) => {
1250-
if (ctx.typeCheck(value)) return value;
1250+
if (ctx.isType(value)) return value;
12511251
return new ObjectId(value);
12521252
});
12531253

‎src/object.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,11 @@ export default class ObjectSchema<
316316
}
317317

318318
return next.withMutation((s: any) =>
319-
s.setFields(nextFields, this._excludedEdges),
319+
// XXX: excludes here is wrong
320+
s.setFields(nextFields, [
321+
...this._excludedEdges,
322+
...schema._excludedEdges,
323+
]),
320324
);
321325
}
322326

‎test/mixed.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ describe('Mixed Types ', () => {
957957
foo: array(number().integer()).required(),
958958
bar: string()
959959
.max(2)
960-
.default(()=> 'a')
960+
.default(() => 'a')
961961
.meta({ input: 'foo' })
962962
.label('str!')
963963
.oneOf(['a', 'b'])
@@ -966,7 +966,7 @@ describe('Mixed Types ', () => {
966966
is: 'entered',
967967
then: (s) => s.defined(),
968968
}),
969-
baz: tuple([string(), number()])
969+
baz: tuple([string(), number()]),
970970
});
971971
});
972972

@@ -1070,7 +1070,7 @@ describe('Mixed Types ', () => {
10701070
oneOf: [],
10711071
notOneOf: [],
10721072
tests: [],
1073-
}
1073+
},
10741074
],
10751075
},
10761076
},
@@ -1182,7 +1182,7 @@ describe('Mixed Types ', () => {
11821182
oneOf: [],
11831183
notOneOf: [],
11841184
tests: [],
1185-
}
1185+
},
11861186
],
11871187
},
11881188
},

‎test/object.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,10 @@ describe('Object types', () => {
10051005
await expect(
10061006
schema.concat(object()).isValid({ a1: null }),
10071007
).resolves.toEqual(false);
1008+
1009+
await expect(
1010+
object().concat(schema).isValid({ a1: null }),
1011+
).resolves.toEqual(false);
10081012
});
10091013

10101014
it('should handle nested conditionals', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.