OpenAPITools / OpenAPITools/openapi-generator

[BUG][powershell] Reusable enum schemas generates invalid .ps1 files

Open
#8,316 3 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: PowerShell Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

I'm defining a reusable enum schema in my OpenAPI 3 spec file and reuse this schema in other schema fields to avoid writing the same enum values multiple times.

This results in generated .ps1 files with an empty expression which PowerShell does not accept:

function ConvertFrom-JsonToApplicationType {
    Param(
        [AllowEmptyString()]
        [string]$Json
    )

    Process {
        'Converting JSON to PSCustomObject: PSOpenAPITools => ApplicationType' | Write-Debug
        $PSBoundParameters | Out-DebugParameter | Write-Debug

        $JsonParameters = ConvertFrom-Json -InputObject $Json

        # check if Json contains properties not defined in ApplicationType
        $AllProperties = ()
        foreach ($name in $JsonParameters.PsObject.Properties.Name) {
            if (!($AllProperties.Contains($name))) {
                throw "Error! JSON key '$name' not found in the properties: $($AllProperties)"
            }
        }

        $PSO = [PSCustomObject]@{
        }

        return $PSO
    }

}

The line of $AllProperties = () generates an error in the Build.ps1 process:

Get-ChildItem : At C:\XXXXX\Model\ApplicationType.ps1:70 char:27
+         $AllProperties = ()
+                           ~
An expression was expected after '('.
openapi-generator version

version 5.0.0

OpenAPI declaration file content or url
components:
  schemas:
    ApplicationType:
      type: string
      enum:
        - direct
        - hosted

##### Generation Details

using the powershell generator without any flags or template configurations.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PowerShell generator output for the provided reusable enum schema and inspect the generated ApplicationType.ps1, especially the $AllProperties assignment and Build.ps1 failure. Reproduce the invalid empty expression from the YAML example, then verify that generated .ps1 files contain valid PowerShell and Build.ps1 completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, powershell
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.