Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .chronus/changes/fix-file-type-interpolation-2026-2-27-10-9-43.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
changeKind: fix
packages:
- "@typespec/compiler"
---

Do not interpolate non primitive values in config automatically
```yaml
file-type: ["json", "yaml"]
output-file: "openapi.{file-type}"
```
Will not be interpolated as `openapi.json,yaml` but keep the placeholder `{file-type}` intact for the emitter to handle.
9 changes: 7 additions & 2 deletions packages/compiler/src/config/config-interpolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ export function resolveValues<T extends Record<string, unknown>>(
resolvingValues.delete(keyPath);
return value;
}
const replaced = value.replace(VariableInterpolationRegex, (_, expression) => {
return (resolveExpression(expression) as string) ?? `{${expression}}`;
const replaced = value.replace(VariableInterpolationRegex, (match, expression) => {
const resolved = resolveExpression(expression);
return typeof resolved === "string" ||
typeof resolved === "number" ||
typeof resolved === "boolean"
? String(resolved)
: match;
});
resolvingValues.delete(keyPath);
return replaced;
Expand Down
26 changes: 26 additions & 0 deletions packages/compiler/test/config/config-interpolation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,32 @@ describe("compiler: config interpolation", () => {
},
]);
});

it("does not interpolate variables that resolve to non-string values", () => {
const [resolved, diagnostics] = resolveValues({
"output-file": "openapi.{file-type}",
"file-type": ["yaml", "json"] as any,
});
expectDiagnosticEmpty(diagnostics);
deepStrictEqual(resolved, {
"output-file": "openapi.{file-type}",
"file-type": ["yaml", "json"],
});
});

it("interpolates number and boolean values", () => {
const [resolved, diagnostics] = resolveValues({
path: "v{version}/debug-{debug}",
version: 3 as any,
debug: true as any,
});
expectDiagnosticEmpty(diagnostics);
deepStrictEqual(resolved, {
path: "v3/debug-true",
version: 3,
debug: true,
});
});
});

describe("expandConfigVariables", () => {
Expand Down
Loading