Skip to content

Commit

Permalink
fix(object): excluded edges are merged when concating schema
Browse files Browse the repository at this point in the history
fixes #1969
  • Loading branch information
jquense committed Apr 14, 2023
1 parent f999497 commit c07b08f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ import { mixed, InferType } from 'yup';
let objectIdSchema = yup
.mixed((input): input is ObjectId => input instanceof ObjectId)
.transform((value: any, input, ctx) => {
if (ctx.typeCheck(value)) return value;
if (ctx.isType(value)) return value;
return new ObjectId(value);
});

Expand Down
6 changes: 5 additions & 1 deletion src/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,11 @@ export default class ObjectSchema<
}

return next.withMutation((s: any) =>
s.setFields(nextFields, this._excludedEdges),
// XXX: excludes here is wrong
s.setFields(nextFields, [
...this._excludedEdges,
...schema._excludedEdges,
]),
);
}

Expand Down
8 changes: 4 additions & 4 deletions test/mixed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ describe('Mixed Types ', () => {
foo: array(number().integer()).required(),
bar: string()
.max(2)
.default(()=> 'a')
.default(() => 'a')
.meta({ input: 'foo' })
.label('str!')
.oneOf(['a', 'b'])
Expand All @@ -966,7 +966,7 @@ describe('Mixed Types ', () => {
is: 'entered',
then: (s) => s.defined(),
}),
baz: tuple([string(), number()])
baz: tuple([string(), number()]),
});
});

Expand Down Expand Up @@ -1070,7 +1070,7 @@ describe('Mixed Types ', () => {
oneOf: [],
notOneOf: [],
tests: [],
}
},
],
},
},
Expand Down Expand Up @@ -1182,7 +1182,7 @@ describe('Mixed Types ', () => {
oneOf: [],
notOneOf: [],
tests: [],
}
},
],
},
},
Expand Down
4 changes: 4 additions & 0 deletions test/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,10 @@ describe('Object types', () => {
await expect(
schema.concat(object()).isValid({ a1: null }),
).resolves.toEqual(false);

await expect(
object().concat(schema).isValid({ a1: null }),
).resolves.toEqual(false);
});

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

0 comments on commit c07b08f

Please sign in to comment.