Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix nullable json schema #31938

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading