From 6c00935e8b2950a9ed933e759c84c3b42760401e Mon Sep 17 00:00:00 2001 From: Sam Chung Date: Mon, 14 Oct 2024 22:50:34 +1100 Subject: [PATCH] docs: fix nullable json schema (#31938) Co-authored-by: Rhys Arkins --- 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 293e713af91ba0..3cafa6d9c30368 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; +type JsonSchemaBasicType = + | 'string' + | 'number' + | 'integer' + | 'boolean' + | 'object' + | 'array' + | 'null'; +type JsonSchemaType = JsonSchemaBasicType | JsonSchemaBasicType[]; + function createSingleConfig(option: RenovateOptions): Record { - const temp: Record & Partial = {}; + const temp: Record & { + type?: JsonSchemaType; + } & Omit, 'type'> = {}; if (option.description) { temp.description = option.description; } @@ -67,7 +79,13 @@ function createSingleConfig(option: RenovateOptions): Record { ) { 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;