[types] added "dontChangeOptional" boolean to avoid changing optional props in SchemaMap#2907
[types] added "dontChangeOptional" boolean to avoid changing optional props in SchemaMap#2907maxgalbu wants to merge 1 commit intohapijs:masterfrom
Conversation
|
I've tried to be as backward compatible as possible. Probably a better solution could be to have |
|
Hi, and sorry for the super late reply. I'm not entirely sure I understand your problem. So it's quite normal that in your example, the missing const schema = Joi.object<AppParams, true, true>({
destination: Joi.string().required(),
destination_latitude: Joi.number().required(),
destination_longitude: Joi.number().required(),
destination_country: Joi.string().required(),
destination_id: Joi.string().required(),
secure: Joi.boolean(),
host: Joi.string()
})The required fields should be required, and the optional ones should be present but without the required property. If you don't care for some properties, then you should do something like |
|
The fact is that the typecheck should be strict but it `should not* overwrite the optional fields... secure and host are optional It should be like this, without the |
|
Optional doesn't mean they can be entirely absent from your schema. If it's part of the type, it should as well be part of the schema, otherwise you should omit them. |
I have a type which has some parameters that come from GET (and requires validation), others are filled later using request headers and protocol and other stuff (which don't require validation).
When trying to use the type when defining the schema, the fact that either all the properties are made optional (PartialSchemaMap), or are mandatory (StrictSchemaMap), makes defining schema types impossible when some parameters doesn't need validation:
joi/lib/index.d.ts
Lines 793 to 801 in 8fc7273
Example:
This pull request would allow this: