mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 03:03:24 -04:00
fix(config): accept $schema key in root config (#15280)
* fix(config): accept $schema key in root config (#14998) * fix: strip $schema via preprocess to avoid spurious UI section * fix(config): allow root without zod preprocess wrapper --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
24
src/config/config.schema-key.test.ts
Normal file
24
src/config/config.schema-key.test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { OpenClawSchema } from "./zod-schema.js";
|
||||
|
||||
describe("$schema key in config (#14998)", () => {
|
||||
it("accepts config with $schema string", () => {
|
||||
const result = OpenClawSchema.safeParse({
|
||||
$schema: "https://openclaw.ai/config.json",
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
if (result.success) {
|
||||
expect(result.data.$schema).toBe("https://openclaw.ai/config.json");
|
||||
}
|
||||
});
|
||||
|
||||
it("accepts config without $schema", () => {
|
||||
const result = OpenClawSchema.safeParse({});
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects non-string $schema", () => {
|
||||
const result = OpenClawSchema.safeParse({ $schema: 123 });
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -7,6 +7,7 @@ describe("config schema", () => {
|
||||
const schema = res.schema as { properties?: Record<string, unknown> };
|
||||
expect(schema.properties?.gateway).toBeTruthy();
|
||||
expect(schema.properties?.agents).toBeTruthy();
|
||||
expect(schema.properties?.$schema).toBeUndefined();
|
||||
expect(res.uiHints.gateway?.label).toBe("Gateway");
|
||||
expect(res.uiHints["gateway.auth.token"]?.sensitive).toBe(true);
|
||||
expect(res.version).toBeTruthy();
|
||||
|
||||
@@ -303,6 +303,12 @@ function stripChannelSchema(schema: ConfigSchema): ConfigSchema {
|
||||
if (!root || !root.properties) {
|
||||
return next;
|
||||
}
|
||||
// Allow `$schema` in config files for editor tooling, but hide it from the
|
||||
// Control UI form schema so it does not show up as a configurable section.
|
||||
delete root.properties.$schema;
|
||||
if (Array.isArray(root.required)) {
|
||||
root.required = root.required.filter((key) => key !== "$schema");
|
||||
}
|
||||
const channelsNode = asSchemaObject(root.properties.channels);
|
||||
if (channelsNode) {
|
||||
channelsNode.properties = {};
|
||||
|
||||
@@ -95,6 +95,7 @@ const MemorySchema = z
|
||||
|
||||
export const OpenClawSchema = z
|
||||
.object({
|
||||
$schema: z.string().optional(),
|
||||
meta: z
|
||||
.object({
|
||||
lastTouchedVersion: z.string().optional(),
|
||||
|
||||
Reference in New Issue
Block a user