Skip to content

Commit

Permalink
Postman Collection: Include parameter description for formdata
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Jun 27, 2022
1 parent 9e3d35d commit 10faa50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/Writing/PostmanCollectionWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ protected function getBodyData(OutputEndpointData $endpoint): array
switch ($inputMode) {
case 'formdata':
case 'urlencoded':
$body[$inputMode] = $this->getFormDataParams($endpoint->cleanBodyParameters);
$body[$inputMode] = $this->getFormDataParams(
$endpoint->cleanBodyParameters, null, $endpoint->bodyParameters
);
foreach ($endpoint->fileParameters as $key => $value) {
while (is_array($value)) {
$keys = array_keys($value);
Expand Down Expand Up @@ -187,18 +189,19 @@ protected function getBodyData(OutputEndpointData $endpoint): array
/**
* Format form-data parameters correctly for arrays eg. data[item][index] = value
*/
protected function getFormDataParams(array $array, ?string $key = null): array
protected function getFormDataParams(array $paramsKeyValue, ?string $key = null, array $paramsFullDetails = []): array
{
$body = [];

foreach ($array as $index => $value) {
foreach ($paramsKeyValue as $index => $value) {
$index = $key ? ($key . '[' . $index . ']') : $index;

if (!is_array($value)) {
$body[] = [
'key' => $index,
'value' => $value,
'type' => 'text',
'description' => $paramsFullDetails[$index]->description ?? '',
];

continue;
Expand Down Expand Up @@ -329,8 +332,7 @@ private function getResponses(OutputEndpointData $endpoint): array
foreach ($response->headers as $header => $value) {
$headers[] = [
'key' => $header,
// Todo remove array support in future
'value' => is_array($value) ? implode('; ', $value) : $value
'value' => $value
];
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Fixtures/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
{
"key": "name",
"value": "cat.jpg",
"type": "text"
"type": "text",
"description": "Name of image."
},
{
"key": "image",
Expand Down

0 comments on commit 10faa50

Please sign in to comment.