mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 14:10:37 -07:00
feat(docs): Ensure multiline JS objects are rendered properly. (#13535)
This commit is contained in:
@@ -168,7 +168,23 @@ function renderSections(sections: Map<string, DocEntry[]>) {
|
||||
for (const entry of entries) {
|
||||
lines.push(`- **\`${entry.path}\`** (${entry.type}):`);
|
||||
lines.push(` - **Description:** ${entry.description}`);
|
||||
lines.push(` - **Default:** \`${escapeBackticks(entry.defaultValue)}\``);
|
||||
|
||||
if (entry.defaultValue.includes('\n')) {
|
||||
lines.push(' - **Default:**');
|
||||
lines.push('');
|
||||
lines.push(' ```json');
|
||||
lines.push(
|
||||
entry.defaultValue
|
||||
.split('\n')
|
||||
.map((line) => ` ${line}`)
|
||||
.join('\n'),
|
||||
);
|
||||
lines.push(' ```');
|
||||
} else {
|
||||
lines.push(
|
||||
` - **Default:** \`${escapeBackticks(entry.defaultValue)}\``,
|
||||
);
|
||||
}
|
||||
|
||||
if (entry.enumValues && entry.enumValues.length > 0) {
|
||||
const values = entry.enumValues
|
||||
|
||||
56
scripts/tests/autogen.test.ts
Normal file
56
scripts/tests/autogen.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { formatDefaultValue } from '../utils/autogen.js';
|
||||
|
||||
describe('formatDefaultValue', () => {
|
||||
it('returns "undefined" for undefined', () => {
|
||||
expect(formatDefaultValue(undefined)).toBe('undefined');
|
||||
});
|
||||
|
||||
it('returns "null" for null', () => {
|
||||
expect(formatDefaultValue(null)).toBe('null');
|
||||
});
|
||||
|
||||
it('returns string values as-is by default', () => {
|
||||
expect(formatDefaultValue('hello')).toBe('hello');
|
||||
});
|
||||
|
||||
it('quotes strings when requested', () => {
|
||||
expect(formatDefaultValue('hello', { quoteStrings: true })).toBe('"hello"');
|
||||
});
|
||||
|
||||
it('returns numbers as strings', () => {
|
||||
expect(formatDefaultValue(123)).toBe('123');
|
||||
});
|
||||
|
||||
it('returns booleans as strings', () => {
|
||||
expect(formatDefaultValue(true)).toBe('true');
|
||||
});
|
||||
|
||||
it('pretty prints arrays', () => {
|
||||
const input = ['a', 'b'];
|
||||
const expected = JSON.stringify(input, null, 2);
|
||||
expect(formatDefaultValue(input)).toBe(expected);
|
||||
expect(formatDefaultValue(input)).toContain('\n');
|
||||
});
|
||||
|
||||
it('returns "[]" for empty arrays', () => {
|
||||
expect(formatDefaultValue([])).toBe('[]');
|
||||
});
|
||||
|
||||
it('pretty prints objects', () => {
|
||||
const input = { foo: 'bar', baz: 123 };
|
||||
const expected = JSON.stringify(input, null, 2);
|
||||
expect(formatDefaultValue(input)).toBe(expected);
|
||||
expect(formatDefaultValue(input)).toContain('\n');
|
||||
});
|
||||
|
||||
it('returns "{}" for empty objects', () => {
|
||||
expect(formatDefaultValue({})).toBe('{}');
|
||||
});
|
||||
});
|
||||
@@ -57,7 +57,7 @@ export function formatDefaultValue(
|
||||
return '[]';
|
||||
}
|
||||
try {
|
||||
return JSON.stringify(value);
|
||||
return JSON.stringify(value, null, 2);
|
||||
} catch {
|
||||
return String(value);
|
||||
}
|
||||
@@ -65,7 +65,7 @@ export function formatDefaultValue(
|
||||
|
||||
if (typeof value === 'object') {
|
||||
try {
|
||||
const json = JSON.stringify(value);
|
||||
const json = JSON.stringify(value, null, 2);
|
||||
if (json === '{}') {
|
||||
return '{}';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user