Skip to content

Commit 0bf2829

Browse files
committed
fix: allow Joi.any().valid(null) to generate null
1 parent 0c6430a commit 0bf2829

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/build/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ export function generateType(schema: Schema, options?: Options): TypeNode {
7979
}
8080

8181
let valids: TypeNode[] = Array.from((schema as ExtendedSchema)._valids?._values ?? new Set()).map((value) => {
82-
// unknown | null is redundant, so just drop the null
83-
if (schema.type === "any" && value === null) {
82+
// unknown | null is redundant, so just drop the null unless this is the only allowed value
83+
if (schema._flags.only !== true && schema.type === "any" && value === null) {
8484
return;
8585
}
8686

8787
// string | "" is redundant, so just drop the ""
88-
if (schema.type === "string" && value === "") {
88+
if (schema._flags.only !== true && schema.type === "string" && value === "") {
8989
return;
9090
}
9191

0 commit comments

Comments
 (0)