Skip to content

Commit

Permalink
docs: fix nullable json schema (#31938)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <[email protected]>
  • Loading branch information
samchungy and rarkins authored Oct 14, 2024
1 parent 5cb1078 commit 6c00935
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions tools/docs/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6c00935

Please sign in to comment.