From d312ec5f63415dbb2b8ba2fb5a4056075249e65f Mon Sep 17 00:00:00 2001 From: toyayuto Date: Thu, 19 Feb 2026 08:59:45 +0900 Subject: [PATCH] fix: rename version query param to avoid global --version flag conflict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit specli (via commander.js) reserves --version as a global flag for displaying the CLI version number. This causes the `version` query parameter on `prompts get` to be unusable — running `langfuse api prompts get my-prompt --version 4` displays "0.0.39" instead of fetching prompt version 4. Rename the parameter to `prompt-version` in patch-openapi.ts so the generated CLI flag becomes `--prompt-version`, avoiding the collision. The rename logic is data-driven via a `paramRenames` map, making it easy to add more renames if other parameters collide in the future. Co-authored-by: Cursor --- scripts/patch-openapi.ts | 61 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/scripts/patch-openapi.ts b/scripts/patch-openapi.ts index 806a4e3..ebe1774 100644 --- a/scripts/patch-openapi.ts +++ b/scripts/patch-openapi.ts @@ -214,9 +214,64 @@ if (paths?.items) { } } -if (patchCount > 0) { +// Rename query parameters that collide with specli's global flags. +// specli (via commander.js) reserves "--version" for CLI version display, +// so any OpenAPI query parameter named "version" becomes unusable. +const paramRenames: Record> = { + prompts_get: { version: "prompt-version" }, +}; + +let renameCount = 0; +if (paths?.items) { + for (const pathPair of paths.items) { + const methods = pathPair.value; + if (!methods?.items) continue; + for (const methodPair of methods.items) { + const op = methodPair.value; + if (!op?.items) continue; + + let operationId = ""; + for (const field of op.items) { + if (field.key?.value === "operationId") { + operationId = field.value?.value ?? ""; + break; + } + } + + const renames = paramRenames[operationId]; + if (!renames) continue; + + for (const field of op.items) { + if (field.key?.value !== "parameters") continue; + const params = field.value; + if (!params?.items) continue; + + for (const param of params.items) { + if (!param?.items) continue; + let nameField: any = null; + let inValue = ""; + for (const pf of param.items) { + if (pf.key?.value === "name") nameField = pf; + if (pf.key?.value === "in") inValue = pf.value?.value ?? ""; + } + const oldName = nameField?.value?.value; + if (oldName && inValue === "query" && renames[oldName]) { + nameField.value = doc.createNode(renames[oldName]); + renameCount++; + console.log( + `Renamed ${operationId} query param '${oldName}' → '${renames[oldName]}'`, + ); + } + } + } + } + } +} + +const dirty = patchCount > 0 || renameCount > 0; +if (dirty) { writeFileSync(specPath, doc.toString({ singleQuote: true })); - console.log(`\nWrote ${patchCount} patched schema(s) to ${specPath}`); + console.log(`\nWrote patched spec to ${specPath} (${patchCount} schema(s), ${renameCount} param rename(s))`); } else { - console.log("No discriminated unions found to patch."); + console.log("No patches needed."); }