Skip to content

[BUG] [PowerShell] Client has invalid comment syntax when using array query parameters #23489

@ppritchard-peer

Description

@ppritchard-peer

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

modules/openapi-generator/src/main/resources/powershell/api_client.mustache has

# construct URL query string
    $HttpValues = [System.Web.HttpUtility]::ParseQueryString([String]::Empty)
    foreach ($Parameter in $QueryParameters.GetEnumerator()) {
        if ($Parameter.Value.Count -gt 1) { // array
            foreach ($Value in $Parameter.Value) {
                $HttpValues.Add($Parameter.Key + '[]', $Value)
            }
        } else {
            $HttpValues.Add($Parameter.Key,$Parameter.Value)
        }
    }

That // array causes an exception:

Invoke-PSApiClient : The term '//' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
openapi-generator version

7.21.0 (been an issue for a long time by the looks of it)

Steps to reproduce

From the sample PowerStore client (samples/client/petstore/powershell) directory:

  1. .\Build.ps1
  2. Import-Module -Name '.\src\PSPetstore' -Verbose
  3. Find-PSPetsByStatus available,pending
Suggest a fix

Replace the // with # for the comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions