Skip to content

Commit

Permalink
Set nested file fields properly in Postman
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Jul 2, 2021
1 parent 3ca2fa9 commit 39d53ea
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Writing/PostmanCollectionWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,16 @@ protected function getBodyData(OutputEndpointData $endpoint): array
case 'formdata':
$body[$inputMode] = $this->getFormDataParams($endpoint->cleanBodyParameters);
foreach ($endpoint->fileParameters as $key => $value) {
while (is_array($value)) { // For arrays of files, just send the first one
$key .= '[]';
$value = $value[0];
while (is_array($value)) {
$keys = array_keys($value);
if ($keys[0] === 0) {
// List of files
$key .= '[]';
$value = $value[0];
} else {
$key .= '['.$keys[0].']';
$value = $value[$keys[0]];
}
}
$params = [
'key' => $key,
Expand Down

0 comments on commit 39d53ea

Please sign in to comment.