OpenAPITools / OpenAPITools/openapi-generator
[Powershell] Not Defined Submodel should be a new PSObject, not Null
Nobody has claimed this yet.
- 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?
Description
Powershell
When generatin a Model which has got Sub Models in it A PSCustomobject is generated to Represent the Sub Model.
This Object is by template definition null when not provided as Parameter.
The Definition does not Mark the Property as nullable.
So the Representation of a not Defined PSoject should be a new PSObject not Null
ALTERNATIVLY : not Defined Properties could be omited when posted as the are not explicite Defined (suggestion below)
openapi-generator version
5.3.0
post
http://api.openapi-generator.tech//api/gen/clients/powershell
BODY
{
"openAPIUrl": "https://demo.netbox.dev/api/docs/?format=openapi",
"options": {"discardReadOnly":"true","packageName":"netbox"}
}
OpenAPI declaration file content or url
https://demo.netbox.dev/api/docs/?format=openapi
Steps to reproduce
generate and unzip Model
Open powershell
import -Module ...PathtoPSm1
set auth token for public demo ; can be found at https://demo.netbox.dev/admin/users/token/
Set-Configuration -DefaultHeaders @{"Authorization"= 'fb4770bf8b4b880b876089fb96fa3bf2b36da8cf'}
$dev = Initialize-WritableDeviceWithConfigContext -DeviceType 7 -DeviceRole 1 -Rack 1 -Site 2 -Position 8
Invoke-DcimDevicesCreate -Data $dev
Suggest a fix
an Option for Powershell generator option like "OmitNotDefinedParameter"
would be placed at line 183
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/powershell/model_simple.mustache
#Hope I get this right
#Used for Mapping Display Name of the Parameter to the Property Name
$DisplayNameMapping =@{
{{#allVars}}"{{{baseName}}}"="{{{name}}}"{{^-last}}; {{/-last}}{{/allVars}}
}
$OBJ = @{}
foreach($parameter in $PSBoundParameters.Keys){
#If Specifield map the Display name back
$DisplayNameMapping.($OBJ.$parameter) = $PSBoundParameters.$parameter
}
$PSO = [PSCustomObject]$OBJ
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 modules/openapi-generator/src/main/resources/powershell/model_simple.mustache around the suggested line 183, then generate and inspect the Powershell model from the provided NetBox OpenAPI URL. Reproduce the behavior with an omitted submodel parameter and determine whether the completed behavior should create a PSObject or omit undefined properties, with generated model output and the corresponding option or default behavior confirming the result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, powershell
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100