OpenAPITools / OpenAPITools/openapi-generator

[BUG][PowerShell] [System.IO.FileInfo] object used in multipart/form-data submission does not support relative paths

Open
#18,428 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

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)

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 in the PowerShell generator templates or entry points responsible for multipart/form-data parameters and [System.IO.FileInfo] handling. Reproduce the issue with a relative path in a generated client, comparing Get-Location with [System.IO.Directory]::GetCurrentDirectory(), and verify the behavior on PowerShell 5 and 7. Done means relative FileInfo paths submit the intended file while absolute paths remain unchanged.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.