swagger-api / swagger-api/swagger-codegen

[PowerShell] Incorrect declaration of parameter type, when the parameter is of type Dictionary/Hashtable.

Open
#6,645 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: PowerShell help wanted Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When using codegen to output PowerShell code based on [X] OpenAPI specification parameters of datatype are not declared in the proper PowerShell syntax. See this attached picture as an example -->

swaggerdictionaryissue_171009

Swagger-codegen
Swagger declaration file content or url

Gist containing the OctopusDeploy OpenAPI implementation json file:

Command line used for generation

java -jar swagger-codegen-cli-2.2.3.jar generate -i ./octopusDeploy.json -o outputfolderName -c config.json

config.json content
{ "packageName": "Danske.Spil.Octopus.Deploy.API" }

Steps to reproduce
  1. Execute the cmdline written under "Swagger declaration file content or url" above.
  2. Open the folder containing the generated code in any IDE
  3. Open for example the file named: "New-AccountResource.ps1". It is located underneath DRIVE:\PATH_TO_OUTPUT_FOLDER\src\IO.Swagger\Model\
Related issues/PRs

Haven't found one. Did a search both in the closed and the open issues.

Suggest a fix/enhancement

As the Dictionary and Hashtable types are almost similar it could be an option to declare a dictionary type as [Hashtable]. So for an PowerShell function parameter it would look like this:
function New-AccountResource { [CmdletBinding()] Param ( [System.Nullable[HashTable]] ${Links} ) ..............

Additional note
  • Why is the API and Model parts of an OpenAPI implementing API being generated into a folder named "IO.Swagger"?
    When the "Private" folder and .psm1 file are generated under a folder respecting the > packageName specified inside the config.json file? See this attached picture as an example:

swaggerdictionaryissue_folderstruct_171009

  • Also, why is the parameter type being declared as [System.Nullable]?

Thank you and I'm looking forward to hear from you. Let me know if there is anything I can elaborate further upon. Have a great day/evening (where ever you are).

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

Run the listed swagger-codegen-cli command with the linked OpenAPI input and inspect src\IO.Swagger\Model\New-AccountResource.ps1. Compare the generated Dictionary/Hashtable parameter declaration with the requested PowerShell syntax, and check whether the [System.Nullable] and packageName folder behavior are part of the same generator output. Done means the generated parameter type is valid PowerShell for dictionary values and the related output behavior is clarified or corrected.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.