for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Mpociot\ApiDoc\Postman;
use Illuminate\Support\Collection;
use Ramsey\Uuid\Uuid;
class CollectionWriter
{
/**
* @var Collection
*/
private $routeGroups;
* CollectionWriter constructor.
* @param Collection $routeGroups
public function __construct(Collection $routeGroups)
$this->routeGroups = $routeGroups;
}
public function getCollection()
$collection = [
'variables' => [],
'info' => [
'name' => '',
'_postman_id' => Uuid::uuid1()->toString(),
'description' => '',
'schema' => 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json'
],
'item' => $this->routeGroups->map(function ($routes, $groupName) {
return [
'name' => $groupName,
'item' => $routes->map(function ($route) {
'name' => $route['title'] != '' ? $route['title'] : url($route['uri']),
'request' => [
'url' => url($route['uri']),
'method' => $route['methods'][0],
'body' => [
'mode' => 'formdata',
'formdata' => collect($route['parameters'])->map(function ($parameter, $key) {
'key' => $key,
'value' => isset($parameter['value']) ? $parameter['value'] : '',
'type' => 'text',
'enabled' => true
];
})->values()->toArray(),
'description' => $route['description'],
'response' => []
]
})->toArray()
})->values()->toArray()
return json_encode($collection);