Skip to content

Commit 4eba061

Browse files
gaurav0107claude
andcommitted
[POWERSHELL] test: assert every baseName emission site is single-quoted
Extends the regression test to cover every place model_simple.mustache embeds a user-supplied property name: the Initialize- hash literal, the ConvertFrom-…JsonTo… hash literal, the $AllProperties allow-list, the .Properties[…] indexer, and the -match presence check. All five must be single-quoted so PowerShell preserves `$` literally. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 66e8a42 commit 4eba061

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

modules/openapi-generator/src/test/java/org/openapitools/codegen/powershell/PowerShellClientCodegenTest.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,26 @@ public void dollarSignPropertyNamesAreSingleQuoted() throws IOException {
7575
// so the emitted model lives at src/<package>/Model/DollarModel.ps1.
7676
java.nio.file.Path dollarModelPs1 = Paths.get(outputPath + "/src/PSOpenAPITools/Model/DollarModel.ps1");
7777

78-
// Property names containing `$` must be single-quoted so PowerShell does
79-
// not attempt variable interpolation.
80-
assertFileContains(dollarModelPs1, "'$dollarValue$'");
78+
// Every site where model_simple.mustache emits a user-supplied baseName
79+
// must use single-quoted PowerShell strings so `$` is treated literally:
80+
//
81+
// 1. The `Initialize-…` hash literal: `'$dollarValue$' = ${DollarValue}`
82+
// 2. The JSON round-trip hash literal in `ConvertFrom-…JsonTo…`
83+
// 3. The property-allowlist array: `$AllProperties = ('$dollarValue$')`
84+
// 4. The property-indexer lookup: `$JsonParameters.PSobject.Properties['$dollarValue$'].value`
85+
// 5. The presence-check regex: `-match '$dollarValue$'`
86+
assertFileContains(dollarModelPs1,
87+
"'$dollarValue$' = ${DollarValue}",
88+
"$AllProperties = ('$dollarValue$')",
89+
"$JsonParameters.PSobject.Properties['$dollarValue$'].value",
90+
"-match '$dollarValue$'");
8191

82-
// The previous double-quoted emission must no longer appear anywhere in
92+
// The previous double-quoted emissions must no longer appear anywhere in
8393
// the generated model file.
84-
assertFileNotContains(dollarModelPs1, "\"$dollarValue$\" = ");
94+
assertFileNotContains(dollarModelPs1,
95+
"\"$dollarValue$\" = ",
96+
"$AllProperties = (\"$dollarValue$\")",
97+
"$JsonParameters.PSobject.Properties[\"$dollarValue$\"]",
98+
"-match \"$dollarValue$\"");
8599
}
86100
}

0 commit comments

Comments
 (0)