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
openapi-generator 7.5 PowerShell client supports submission of multipart/form-data
via Invoke-RestMethod
. In particular, the -Form
parameter supports file contents. From the Invoke-RestMethod
documentation:
If the value is a System.IO.FileInfo object, then the binary file contents will be submitted. The name of the file will be submitted as the filename.
Unfortunately the value of the path is correct only when the input path is absolute. The issue is due to the fact that, when the path is relative, the full path is calculated using as directory the value returned by [System.IO.Directory]::GetCurrentDirectory()
, which is a constant rather than the value returned by Get-Location
.
openapi-generator version
openapi-generator-cli 7.5.0
OpenAPI declaration file content or url
The issue was first noticed using a PowerShell client generated from Connectwise PSA API specs. The specs are too complex (over 4K endpoints) to be used for an example.
Generation Details
openapi-generator generate --input-spec SPECS/2024.1/All.json --generator-name powershell --output PSClient --additional-properties=packageName=CWPSA,packageVersion=2024.1,apiNamePrefix=PSA --skip-validate-spec
Steps to reproduce
The behaviour can be verified on a PowerShell console:
PS /Users/condorcorde/Git/cwpsa-client-frmw-ps> dir ./Build.sh
Directory: /Users/condorcorde/Git/cwpsa-client-frmw-ps
UnixMode User Group LastWriteTime Size Name
-------- ---------- ----- ------------- ---- ----
-rwxr-xr-x condorcorde staff 04.09.2023 17:11 1047 Build.sh
PS /Users/condorcorde/Git/cwpsa-client-frmw-ps> $f = [System.IO.FileInfo]::new('./Build.sh')
PS /Users/condorcorde/Git/cwpsa-client-frmw-ps> $f.FullName
/Users/condorcorde/Build.sh
PS /Users/condorcorde/Git/cwpsa-client-frmw-ps> [System.IO.Directory]::GetCurrentDirectory()
/Users/condorcorde
Related issues/PRs
None found
Suggest a fix
A possibility - compatible with both PS5 and PS7 - would be to transform parameters of type [System.IO.FileInfo]
to make sure that the resulting path is absolute:
$File = $executionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($File)