From 6c00935e8b2950a9ed933e759c84c3b42760401e Mon Sep 17 00:00:00 2001
From: Sam Chung <samchungy@gmail.com>
Date: Mon, 14 Oct 2024 22:50:34 +1100
Subject: [PATCH] docs: fix nullable json schema (#31938)

Co-authored-by: Rhys Arkins <rhys@arkins.net>
---
 tools/docs/schema.ts | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/tools/docs/schema.ts b/tools/docs/schema.ts
index 293e713af9..3cafa6d9c3 100644
--- a/tools/docs/schema.ts
+++ b/tools/docs/schema.ts
@@ -21,8 +21,20 @@ options.sort((a, b) => {
 });
 const properties = schema.properties as Record<string, any>;
 
+type JsonSchemaBasicType =
+  | 'string'
+  | 'number'
+  | 'integer'
+  | 'boolean'
+  | 'object'
+  | 'array'
+  | 'null';
+type JsonSchemaType = JsonSchemaBasicType | JsonSchemaBasicType[];
+
 function createSingleConfig(option: RenovateOptions): Record<string, unknown> {
-  const temp: Record<string, any> & Partial<RenovateOptions> = {};
+  const temp: Record<string, any> & {
+    type?: JsonSchemaType;
+  } & Omit<Partial<RenovateOptions>, 'type'> = {};
   if (option.description) {
     temp.description = option.description;
   }
@@ -67,7 +79,13 @@ function createSingleConfig(option: RenovateOptions): Record<string, unknown> {
   ) {
     temp.additionalProperties = option.additionalProperties;
   }
-  if (temp.type === 'object' && !option.freeChoice) {
+  if (option.default === null) {
+    temp.type = [option.type, 'null'];
+  }
+  if (
+    (temp.type === 'object' || temp.type?.includes('object')) &&
+    !option.freeChoice
+  ) {
     temp.$ref = '#';
   }
   return temp;
-- 
GitLab