mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-18 06:08:22 +03:00
add null to enum list when unwrapping
This commit is contained in:
parent
2ca5d20320
commit
df52529927
@ -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 {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user