Skip to content

fix(scripts): Fix "undefined Options: ..." in generated JSON schema for enum settings without descriptions.#2963

Open
chinesepowered wants to merge 1 commit intoQwenLM:mainfrom
chinesepowered:fix/settings-schema-enum-description
Open

fix(scripts): Fix "undefined Options: ..." in generated JSON schema for enum settings without descriptions.#2963
chinesepowered wants to merge 1 commit intoQwenLM:mainfrom
chinesepowered:fix/settings-schema-enum-description

Conversation

@chinesepowered
Copy link
Copy Markdown
Contributor

@chinesepowered chinesepowered commented Apr 7, 2026

Fix "undefined Options: ..." in generated JSON schema for enum settings without descriptions.

TLDR

scripts/generate-settings-schema.ts only assigned schema.description when the setting had a description, then appended enum options with +=. For enum settings missing a description, the += ran against undefined and produced the literal string "undefined Options: foo, bar" in the generated JSON schema. This PR initializes the field cleanly instead of concatenating onto undefined.

Screenshots / Video Demo

Before (generated JSON schema entry):

{
  "type": "string",
  "enum": ["fast", "accurate"],
  "description": "undefined Options: fast, accurate"
}

After:

{
  "type": "string",
  "enum": ["fast", "accurate"],
  "description": "Options: fast, accurate"
}

Dive Deeper

convertSettingToJsonSchema initializes schema as an empty object, then conditionally assigns description:

const schema: JsonSchemaProperty = {};                       // line 97

if (setting.description) {
  schema.description = setting.description;                 // only if truthy
}

Later, for the 'enum' case:

case 'enum':
  if (setting.options && setting.options.length > 0) {
    schema.enum = setting.options.map((o) => o.value);
    schema.description +=                                    // line 124 — BUG
      ' Options: ' + setting.options.map((o) => `${o.value}`).join(', ');
  }

For any enum setting declared without a description, schema.description is undefined at the point of +=, and JavaScript coerces to "undefined Options: fast, accurate".

The fix initializes cleanly:

case 'enum':
  if (setting.options && setting.options.length > 0) {
    schema.enum = setting.options.map((o) => o.value);
    const optionsText =
      'Options: ' + setting.options.map((o) => `${o.value}`).join(', ');
    schema.description = schema.description
      ? `${schema.description} ${optionsText}`
      : optionsText;
  }

Settings that already had a description are unaffected — only the previously-broken undefined path changes.

Modified file:

  • scripts/generate-settings-schema.ts — initialize schema.description cleanly for enums

Reviewer Test Plan

  1. Regenerate the settings schema: pnpm tsx scripts/generate-settings-schema.ts (or whatever the project's generation command is)
  2. Grep the generated JSON for "undefined Options:" — should be empty
  3. Grep for any enum with an existing description (e.g. check one from packages/cli/src/config/settingsSchema.ts) — verify it still reads "<original description> Options: ..."
  4. Open the regenerated schema and spot-check a few enum entries

Testing Matrix

macOS Windows Linux
npm run ? pass ?
npx ? ? ?
Docker ? ? ?
Podman ? - -
Seatbelt ? - -

…ption

schema.description is only assigned when setting.description is truthy.
For enum settings missing a description, the subsequent += produced the
literal string 'undefined Options: foo, bar' in the generated JSON
schema. Initialize the field when absent instead of concatenating onto
undefined.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant