Skip to content

[POWERSHELL] fix: single-quote DTO property names to prevent $-variable interpolation#23624

Merged
wing328 merged 4 commits intomasterfrom
gaurav0107-fix/23535-powershell-dollar-property-names
Apr 26, 2026
Merged

[POWERSHELL] fix: single-quote DTO property names to prevent $-variable interpolation#23624
wing328 merged 4 commits intomasterfrom
gaurav0107-fix/23535-powershell-dollar-property-names

Conversation

@wing328
Copy link
Copy Markdown
Member

@wing328 wing328 commented Apr 26, 2026

based on #23622

fixes #23535

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Quote all generated PowerShell model property names with single quotes to prevent $-variable interpolation, fixing DTO (de)serialization for names like $ref, $schema, and $type. Adds a regression test and updates samples; fixes #23535.

  • Bug Fixes
    • In powershell/model_simple.mustache, emit user property names as single-quoted literals in PSCustomObject keys, the $AllProperties allow-list, .Properties['...'] indexers, and -match '...' presence checks.
    • Added PowerShellClientCodegenTest to assert single-quoted emission at all sites; regenerated samples to reflect the change.

Written for commit cf4a552. Summary will update on new commits.

gaurav0107 and others added 4 commits April 25, 2026 20:07
…le interpolation

PowerShell treats `$` inside double-quoted strings as the sigil for variable
interpolation, so `"$foo" = ${Foo}` inside a hash literal becomes `<value-of-$foo> = <value-of-Foo>`.
When an OpenAPI property name starts with (or contains) `$` — e.g. `$type` from
C# polymorphic payloads or `$ref` / `$schema` from JSON Schema — the generated
Initialize- and ConvertFrom- commandlets emit invalid PSCustomObject hash keys
and empty regex patterns, breaking DTO (de)serialization.

Swap all user-property-name emissions in `model_simple.mustache` from
double-quoted to single-quoted literals so baseName is preserved verbatim:

- `$PSO = [PSCustomObject]@{ '<baseName>' = ${<name>} }` (3 sites)
- `$AllProperties = ('<baseName>', ...)` (1 site)
- `-match '<baseName>'` and `.Properties['<baseName>']` (4 sites)

Fixes: #23535
Co-Authored-By: Claude <noreply@anthropic.com>
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>
@wing328 wing328 changed the title Gaurav0107 fix/23535 powershell dollar property names [POWERSHELL] fix: single-quote DTO property names to prevent $-variable interpolation Apr 26, 2026
@wing328 wing328 marked this pull request as ready for review April 26, 2026 03:28
@wing328 wing328 added this to the 7.22.0 milestone Apr 26, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 73 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="samples/client/petstore/powershell/src/PSPetstore/Model/SpecialModelName.ps1">

<violation number="1" location="samples/client/petstore/powershell/src/PSPetstore/Model/SpecialModelName.ps1:89">
P1: Use exact name matching instead of regex for `$special[property.name]`; `-match` misinterprets regex characters and can drop a present property during deserialization.</violation>
</file>

<file name="samples/client/petstore/powershell/src/PSPetstore/Model/Order.ps1">

<violation number="1" location="samples/client/petstore/powershell/src/PSPetstore/Model/Order.ps1:114">
P2: Use exact property-name membership instead of `-match` for presence checks; `-match 'id'` also matches `petId`, causing incorrect detection.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

}

if (!([bool]($JsonParameters.PSobject.Properties.name -match "$special[property.name]"))) { #optional property not found
if (!([bool]($JsonParameters.PSobject.Properties.name -match '$special[property.name]'))) { #optional property not found
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Use exact name matching instead of regex for $special[property.name]; -match misinterprets regex characters and can drop a present property during deserialization.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/powershell/src/PSPetstore/Model/SpecialModelName.ps1, line 89:

<comment>Use exact name matching instead of regex for `$special[property.name]`; `-match` misinterprets regex characters and can drop a present property during deserialization.</comment>

<file context>
@@ -79,28 +79,28 @@ function ConvertFrom-PSJsonToSpecialModelName {
         }
 
-        if (!([bool]($JsonParameters.PSobject.Properties.name -match "$special[property.name]"))) { #optional property not found
+        if (!([bool]($JsonParameters.PSobject.Properties.name -match '$special[property.name]'))) { #optional property not found
             $SpecialPropertyName = $null
         } else {
</file context>
Suggested change
if (!([bool]($JsonParameters.PSobject.Properties.name -match '$special[property.name]'))) { #optional property not found
if (!($JsonParameters.PSobject.Properties.name -contains '$special[property.name]')) { #optional property not found
Fix with Cubic

}

if (!([bool]($JsonParameters.PSobject.Properties.name -match "id"))) { #optional property not found
if (!([bool]($JsonParameters.PSobject.Properties.name -match 'id'))) { #optional property not found
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Use exact property-name membership instead of -match for presence checks; -match 'id' also matches petId, causing incorrect detection.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/powershell/src/PSPetstore/Model/Order.ps1, line 114:

<comment>Use exact property-name membership instead of `-match` for presence checks; `-match 'id'` also matches `petId`, causing incorrect detection.</comment>

<file context>
@@ -104,56 +104,56 @@ function ConvertFrom-PSJsonToOrder {
         }
 
-        if (!([bool]($JsonParameters.PSobject.Properties.name -match "id"))) { #optional property not found
+        if (!([bool]($JsonParameters.PSobject.Properties.name -match 'id'))) { #optional property not found
             $Id = $null
         } else {
</file context>
Suggested change
if (!([bool]($JsonParameters.PSobject.Properties.name -match 'id'))) { #optional property not found
if ($JsonParameters.PSobject.Properties.Name -notcontains 'id') { #optional property not found
Fix with Cubic

@wing328 wing328 merged commit b3629fc into master Apr 26, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][POWERSHELL] Properties which start with $ lead to invalid DTO commandlets

2 participants