Skip to content

[BUG][POWERSHELL] Properties which start with $ lead to invalid DTO commandlets #23535

@DesselBane

Description

@DesselBane

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

When there are any properties whos the names start with $ the generated Dto commandlets contain invalid code. $type is the default name of C# polymorphicly serialized classes/dtos.

{
  "properties": {
    "$type": {
	  "type": "string",
	  "enum": ["Dog", "Cat", "Fish"]
    }
  }
}

Invalid PS commandlet

$PSO = [PSCustomObject]@{
	"$type"     = ${Type} 
	"id"        = ${Id}
	"name"      = ${Name}
	"category"  = ${Category}
	"photoUrls" = ${PhotoUrls}
	"tags"      = ${Tags}
	"status"    = ${Status}
}

Since in pwsh "$type" wants to expand the type variable instead of setting $type as the name of the prop

The generated code should probably look like this:

$PSO = [PSCustomObject]@{
	'$type'     = ${Type}
	'id'        = ${Id}
	'name'      = ${Name}
	'category'  = ${Category}
	'photoUrls' = ${PhotoUrls}
	'tags'      = ${Tags}
	'status'    = ${Status}
}
openapi-generator version

7.22.0-SNAPSHOT

Reproduction Repo

https://github.com/DesselBane/repro-pwsh-gen-dollar-bug

OpenAPI declaration file content or url

https://github.com/DesselBane/repro-pwsh-gen-dollar-bug/blob/master/openapi.json#L806

Generation Details

https://github.com/DesselBane/repro-pwsh-gen-dollar-bug/blob/master/generate.ps1

Steps to reproduce
  • clone repo
  • run generate.ps1
  • run run.ps1
  • run test.ps1 <- this is where the error happens
Suggest a fix
  • replace contents of generated/src/PSOpenAPITools/Model/Pet.ps1 with Pet-Fixed.ps1
  • run run.ps1
  • run test.ps1

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