joi
joi copied to clipboard
Joi.date().min(Joi.ref('field')) breaks original sended object
Support plan
- is this issue currently blocking your project? (yes/no): yes
- is this issue affecting a production system? (yes/no): yes
Context
- node version: 19.6.0
- module version with issue: 17.9.1
- last module version without issue: i don't tested in other module
- environment (e.g. node, browser, native): node
- used with (e.g. hapi application, another framework, standalone, ...): expressjs
- any other relevant information:
What are you trying to achieve or the steps to reproduce?
const Joi = require('joi');
const input = {
query: {
periodStart: "2023-02-11T14:23:03.576Z",
periodEnd: "2023-03-23T14:23:03.576Z",
}
}
const schema = Joi.object({
query: Joi.object({
periodStart: Joi.date(),
periodEnd: Joi.date().min(Joi.ref('query.periodStart')).max('now'),
}),
}).options({
allowUnknown: true,
abortEarly: false
})
await schema.validateAsync(input)
What was the result you got?
const receivedResult = {
query: {}
}
What result did you expect?
const expectedResult = {
query: {
periodStart: new Date("2023-02-11T14:23:03.576Z"),
periodEnd: new Date("2023-03-23T14:23:03.576Z"),
}
}
Hey @leandroluk. References are relative to the parent of the current value. Try removing the query.
prefix from your reference :)
@jonathansamines is right, and even with that fix, I can't reproduce your issue. Can you please provide a reproducible case?