hapijs / hapijs/joi

Sets the value at path of object with .rename

Open
#2,632 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
21.2k
Forks
1.5k
Avg merge
4h 57m
Merged PRs (30d)
14

Description

#### Support plan

* *is this issue currently blocking your project?* (yes/no): no
* *is this issue affecting a production system?* (yes/no): no

#### Context

* *node version*: 12.21.0
* *module version*: 17.4.0
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): standalone
* *any other relevant information*:

#### How can we help?

I'm trying to figure out weather or not is it possible for [rename](https://joi.dev/api/?v=17.4.0#objectrenamefrom-to-options) method to work as lodash [set](https://lodash.com/docs/4.17.15#set) method.

```ts
import Joi from "joi";

const FacetsRangeSchema = Joi.object({
from: Joi.string(),
to: Joi.string(),
});

const FacetsSchema = Joi.object({
priceValue: FacetsRangeSchema,
});

const SearchRequestBodySchemaOutput = Joi.object({
productsFacets: Joi.object({
facets: FacetsSchema,
}),
}).rename("priceFrom", "productsFacets.facets.priceValue.from");

const response = SearchRequestBodySchemaOutput.validate({ priceFrom: "100" }, { stripUnknown: false, allowUnknown: true });

console.log(response.value)
```

That output that I would like to see would be

```json
{
"productsFacets": {
"facets": {
"priceValue": {
"to": "100"
}
}
}
}
```

but instead, I get

```
{
"productsFacets.facets.priceValue.to": 100
}
```

Is there any other modifier that I could apply to achieve this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.