Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #8502
Closed
Open
Issue created Jan 21, 2021 by Administrator@rootContributor

Invalid Powershell code generated

Created by: condorcorde

Description

I have tried the powershell client generator with two openAPI input files and the generated code does not build for (at least) two different issues.

The first is backtick characters surrounding name of parameters in many throw statements, e.g.

       if (!([bool]($JsonParameters.PSobject.Properties.name -match "url"))) {
            throw "Error! JSON cannot be serialized due to the required property `url` missing."
        } else {

Most occurrences are ignored, but `u is interpreted as the beginning of a Unicode sequence and raises an error message:

Line |
  64 |  … nctionsToExport = $FunctionPath | Get-ChildItem -Filter *.ps1 | Get-F …
     |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | At /tmp/src/CWManage/Model/ConnectWiseHostedSetup.ps1:217 char:82 + … or!
     | JSON cannot be serialized due to the required property `url` miss … +                                               
     | ~~ The Unicode escape sequence is not valid. A valid sequence is `u{ followed by one to six hex digits and a closing
     | '}'.

The second error is a parameter being declared twice with the same name ($Metadata):

<#
.SYNOPSIS

No summary available.

.DESCRIPTION



.PARAMETER Extras
No description available.
.PARAMETER MetaData
No description available.
.PARAMETER Metadata
No description available.
.PARAMETER Operator
No description available.
.PARAMETER Values
No description available.
.OUTPUTS

Criterion<PSCustomObject>
#>

function Initialize-Criterion {
    [CmdletBinding()]
    Param (
        [Parameter(Position = 0, ValueFromPipelineByPropertyName = $true)]
        [PSCustomObject]
        ${Extras},
        [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true)]
        [PSCustomObject]
        ${MetaData},
        [Parameter(Position = 2, ValueFromPipelineByPropertyName = $true)]
        [PSCustomObject]
        ${Metadata},
        [Parameter(Position = 3, ValueFromPipelineByPropertyName = $true)]

Causing the error below

Line |
  65 |  … nctionsToExport = $FunctionPath | Get-ChildItem -Filter *.ps1 | Get-F …
     |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | At /tmp/src/InsightVM/Model/Criterion.ps1:44 char:9 +        
     | ${Metadata}, +         ~~~~~~~~~~~ Duplicate parameter $Metadata in parameter list. At
     | /Users/amiotto/Documents/API/InsightVM/insightvm-3.0/src/InsightVM/Model/Criterion.ps1:62 char:13 +            
     | "metadata" = ${Metadata} +             ~~~~~~~~~~ Duplicate keys 'metadata' are not allowed in hash literals. At
     | /Users/amiotto/Documents/API/InsightVM/insightvm-3.0/src/InsightVM/Model/Criterion.ps1:142 char:13 +            
     | "metadata" = ${Metadata} +             ~~~~~~~~~~ Duplicate keys 'metadata' are not allowed in hash literals.
openapi-generator version

5.0.0

OpenAPI declaration file content or url

Both errors can be reproduced with this file:

https://help.rapid7.com/insightvm/en-us/api/api.json

Command line used for generation

openapi-generator generate --generator-name powershell --input-spec V3/api.json --additional-properties=packageName=InsightVM,packageVersion=3.0 --output insightvm-3.0 --skip-validate-spec

Steps to reproduce
  1. Generate the code with openapi-generator
  2. Launch Build.ps1
Related issues/PRs

I could not find anything in open issues.

Suggest a fix/enhancement

The backtick in the throw string should be replaced by a quote character.

Assignee
Assign to
Time tracking