mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-24 03:54:43 -07:00
fix(core): support snake_case in policy settings schema
This commit is contained in:
@@ -25,22 +25,42 @@ export const MCPServerConfigSchema = z.object({
|
||||
/**
|
||||
* Zod schema for PolicySettings.
|
||||
*/
|
||||
export const PolicySettingsSchema = z.object({
|
||||
mcp: z
|
||||
.object({
|
||||
excluded: z.array(z.string()).optional(),
|
||||
allowed: z.array(z.string()).optional(),
|
||||
})
|
||||
.optional(),
|
||||
tools: z
|
||||
.object({
|
||||
exclude: z.array(z.string()).optional(),
|
||||
allowed: z.array(z.string()).optional(),
|
||||
})
|
||||
.optional(),
|
||||
mcpServers: z.record(z.object({ trust: z.boolean().optional() })).optional(),
|
||||
policyPaths: z.array(z.string()).optional(),
|
||||
workspacePoliciesDir: z.string().optional(),
|
||||
});
|
||||
export const PolicySettingsSchema = z.preprocess(
|
||||
(val) => {
|
||||
if (typeof val === 'object' && val !== null) {
|
||||
const v = val as Record<string, unknown>;
|
||||
// Map snake_case to camelCase
|
||||
if (v.policy_paths && !v.policyPaths) {
|
||||
v.policyPaths = v.policy_paths;
|
||||
}
|
||||
if (v.workspace_policies_dir && !v.workspacePoliciesDir) {
|
||||
v.workspacePoliciesDir = v.workspace_policies_dir;
|
||||
}
|
||||
if (v.mcp_servers && !v.mcpServers) {
|
||||
v.mcpServers = v.mcp_servers;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
},
|
||||
z.object({
|
||||
mcp: z
|
||||
.object({
|
||||
excluded: z.array(z.string()).optional(),
|
||||
allowed: z.array(z.string()).optional(),
|
||||
})
|
||||
.optional(),
|
||||
tools: z
|
||||
.object({
|
||||
exclude: z.array(z.string()).optional(),
|
||||
allowed: z.array(z.string()).optional(),
|
||||
})
|
||||
.optional(),
|
||||
mcpServers: z
|
||||
.record(z.object({ trust: z.boolean().optional() }))
|
||||
.optional(),
|
||||
policyPaths: z.array(z.string()).optional(),
|
||||
workspacePoliciesDir: z.string().optional(),
|
||||
}),
|
||||
);
|
||||
|
||||
export const MCPServersConfigSchema = z.record(MCPServerConfigSchema);
|
||||
|
||||
Reference in New Issue
Block a user