Conversation
…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>
…github.com/gaurav0107/openapi-generator into gaurav0107-fix/23535-powershell-dollar-property-names
Contributor
There was a problem hiding this comment.
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 |
Contributor
There was a problem hiding this comment.
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 |
| } | ||
|
|
||
| if (!([bool]($JsonParameters.PSobject.Properties.name -match "id"))) { #optional property not found | ||
| if (!([bool]($JsonParameters.PSobject.Properties.name -match 'id'))) { #optional property not found |
Contributor
There was a problem hiding this comment.
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 |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
based on #23622
fixes #23535
PR checklist
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.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)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.
powershell/model_simple.mustache, emit user property names as single-quoted literals in PSCustomObject keys, the$AllPropertiesallow-list,.Properties['...']indexers, and-match '...'presence checks.PowerShellClientCodegenTestto assert single-quoted emission at all sites; regenerated samples to reflect the change.Written for commit cf4a552. Summary will update on new commits.