add null to enum list when unwrapping

This commit is contained in:
Josh Hawkins 2026-02-07 17:09:04 -06:00
parent 2ca5d20320
commit df52529927

View File

@ -97,11 +97,17 @@ function normalizeNullableSchema(schema: RJSFSchema): RJSFSchema {
? [nonNullType, "null"] ? [nonNullType, "null"]
: ["null"]; : ["null"];
const { anyOf: _anyOf, oneOf: _oneOf, ...rest } = schemaObj; const { anyOf: _anyOf, oneOf: _oneOf, ...rest } = schemaObj;
return { const merged: Record<string, unknown> = {
...rest, ...rest,
...normalizedNonNullObj, ...normalizedNonNullObj,
type: mergedType, type: mergedType,
} as RJSFSchema; };
// When unwrapping a nullable enum, add null to the enum list so
// JSON Schema validation accepts the null default value.
if (Array.isArray(merged.enum)) {
merged.enum = [...(merged.enum as unknown[]), null];
}
return merged as RJSFSchema;
} }
return { return {
@ -135,11 +141,16 @@ function normalizeNullableSchema(schema: RJSFSchema): RJSFSchema {
? [nonNullType, "null"] ? [nonNullType, "null"]
: ["null"]; : ["null"];
const { anyOf: _anyOf, oneOf: _oneOf, ...rest } = schemaObj; const { anyOf: _anyOf, oneOf: _oneOf, ...rest } = schemaObj;
return { const merged: Record<string, unknown> = {
...rest, ...rest,
...normalizedNonNullObj, ...normalizedNonNullObj,
type: mergedType, type: mergedType,
} as RJSFSchema; };
// When unwrapping a nullable oneOf enum, add null to the enum list.
if (Array.isArray(merged.enum)) {
merged.enum = [...(merged.enum as unknown[]), null];
}
return merged as RJSFSchema;
} }
return { return {