OpenAPITools / OpenAPITools/openapi-generator
Invalid Powershell code generated
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
- Generate the code with openapi-generator
- 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the PowerShell generator using the provided Rapid7 OpenAPI document and generation command, then run Build.ps1 on the output. Trace how required-property error messages and case-insensitive parameter names are rendered. Done means the generated client builds without invalid backtick escapes, duplicate parameters, or duplicate hash keys.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100