Skip to content

fix(powershell): replace UrlEncode with System.Uri EscapeDataString for path parameter encoding - #24604

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
Mattias-Sehlstedt:encode-powershell-path-parameters
Aug 4, 2026
Merged

fix(powershell): replace UrlEncode with System.Uri EscapeDataString for path parameter encoding#24604
wing328 merged 1 commit into
OpenAPITools:masterfrom
Mattias-Sehlstedt:encode-powershell-path-parameters

Conversation

@Mattias-Sehlstedt

@Mattias-Sehlstedt Mattias-Sehlstedt commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Path parameters are currently encoded with UrlEncode, but in the documentation there is a remark for how it will handle spaces, and it suggests to instead use UrlPathEncode.

Edit: The solution has been adjusted to using System.Uri and EscapeDataString based on feedback. This since UrlPathEncode is designed for full path construction and not the path-by-path template building that is occurring in code.

Could be considered a breaking change if someone relies on a space being encoded as + rather than the usual %20. The current behavior comes from #9688.

Fixes: #24602

PR checklist

  • Read the contribution guidelines.
  • 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.
  • 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

Corrected path parameter encoding in PowerShell clients so spaces encode as %20 and “+” is no longer used. Replaced UrlEncode with [System.Uri]::EscapeDataString to follow .NET guidance (fixes #24602).

  • Bug Fixes

    • Update PowerShell api.mustache to encode path params with [System.Uri]::EscapeDataString([string]$param).
    • Add a test to verify escaping in generated scripts; regenerate samples.
  • Migration

    • Spaces in path params now encode as %20 instead of +. Update expectations or pin the previous generator version.

Written for commit 60588c8. Summary will update on new commits.

Review in cubic

@Mattias-Sehlstedt

Copy link
Copy Markdown
Contributor Author

@FeckNeck could you try changing the api.mustache locally and verifying that this solves your issue?

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 6 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread modules/openapi-generator/src/main/resources/powershell/api.mustache Outdated
Comment thread samples/client/petstore/powershell/src/PSPetstore/Api/PSUserApi.ps1 Outdated
Comment thread samples/client/petstore/powershell/src/PSPetstore/Api/PSStoreApi.ps1 Outdated
Comment thread samples/client/echo_api/powershell/src/PSOpenAPITools/Api/PathApi.ps1 Outdated
@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the encode-powershell-path-parameters branch from 2a14284 to 7588ce6 Compare August 4, 2026 10:18
@Mattias-Sehlstedt Mattias-Sehlstedt changed the title fix(powershell): replace UrlEncode with UrlPathEncode for path parameters fix(powershell): replace UrlEncode with System.Uri EscapeDataString for path parameter encoding Aug 4, 2026
@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the encode-powershell-path-parameters branch from 7588ce6 to 60588c8 Compare August 4, 2026 10:30

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 6 files

Re-trigger cubic

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 6 files

Re-trigger cubic

@wing328
wing328 merged commit e348139 into OpenAPITools:master Aug 4, 2026
17 checks passed
@wing328 wing328 added this to the 7.25.0 milestone Aug 4, 2026
@Mattias-Sehlstedt
Mattias-Sehlstedt deleted the encode-powershell-path-parameters branch August 4, 2026 15:02
@FeckNeck

FeckNeck commented Aug 5, 2026

Copy link
Copy Markdown

@FeckNeck could you try changing the api.mustache locally and verifying that this solves your issue?

Sorry for the late reply. I'm still quite new to OpenAPI Generator, actually.
Could you please clarify exactly what you'd like me to do ?
Anyways, I tested by replacing UrlEncode with System.Uri EscapeDataString and it's working as intented.
Thank you very much for the PR !

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] URLEncode: space encoded as \u002B (+) instead of %20 in HTTP request

3 participants