Ver Fonte

Specify more Postman parameters

Name and description of Postman collection can be specified
Enrico Werkema há 6 anos atrás
pai
commit
14afe077e9

+ 1 - 1
README.md

@@ -45,7 +45,7 @@ Before you can generate your documentation, you'll need to configure a few thing
 This is the file path where the generated documentation will be written to. Default: **public/docs**
 
 - `postman`
-Set this option to true if you want a Postman collection to be generated along with the documentation. Default: **true**
+This is where you specify the Postman collection to be generated along with the documentation. Default: **enabled**
 
 - `router`
 The router to use when processing the route (can be Laravel or Dingo. Defaults to **Laravel**)

+ 16 - 1
config/apidoc.php

@@ -15,7 +15,22 @@ return [
     /*
      * Generate a Postman collection in addition to HTML docs.
      */
-    'postman' => true,
+    'postman' => [
+        /*
+         * Specify whether the Postman collection should be generated.
+         */
+        'enabled' => true,
+
+        /*
+         * The name for the exported Postman collection. Default: config('APP_NAME') API
+         */
+        'name' => null,
+
+        /*
+         * The description for the exported Postman collection.
+         */
+        'description' => null,
+    ],
 
     /*
      * The routes for which documentation should be generated.

+ 4 - 4
src/Commands/GenerateDocumentation.php

@@ -79,7 +79,7 @@ class GenerateDocumentation extends Command
 
         $infoText = view('apidoc::partials.info')
             ->with('outputPath', ltrim($outputPath, 'public/'))
-            ->with('showPostmanCollectionButton', config('apidoc.postman'));
+            ->with('showPostmanCollectionButton', config('apidoc.postman.enabled') ?? config('apidoc.postman'));
 
         $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) {
             return $routeGroup->map(function ($route) {
@@ -135,7 +135,7 @@ class GenerateDocumentation extends Command
             ->with('prependMd', $prependFileContents)
             ->with('appendMd', $appendFileContents)
             ->with('outputPath', config('apidoc.output'))
-            ->with('showPostmanCollectionButton', config('apidoc.postman'))
+            ->with('showPostmanCollectionButton', config('apidoc.postman.enabled') ?? config('apidoc.postman'))
             ->with('parsedRoutes', $parsedRouteOutput);
 
         if (! is_dir($outputPath)) {
@@ -153,7 +153,7 @@ class GenerateDocumentation extends Command
             ->with('prependMd', $prependFileContents)
             ->with('appendMd', $appendFileContents)
             ->with('outputPath', config('apidoc.output'))
-            ->with('showPostmanCollectionButton', config('apidoc.postman'))
+            ->with('showPostmanCollectionButton', config('apidoc.postman.enabled') ?? config('apidoc.postman'))
             ->with('parsedRoutes', $parsedRouteOutput);
 
         file_put_contents($compareFile, $compareMarkdown);
@@ -166,7 +166,7 @@ class GenerateDocumentation extends Command
 
         $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html');
 
-        if (config('apidoc.postman')) {
+        if (config('apidoc.postman.enabled') ?? config('apidoc.postman')) {
             $this->info('Generating Postman collection');
 
             file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes));

+ 2 - 2
src/Postman/CollectionWriter.php

@@ -27,9 +27,9 @@ class CollectionWriter
         $collection = [
             'variables' => [],
             'info' => [
-                'name' => '',
+                'name' => config('apidoc.postman.name') ?: config('app.name').' API',
                 '_postman_id' => Uuid::uuid4()->toString(),
-                'description' => '',
+                'description' => config('apidoc.postman.description') ?: '',
                 'schema' => 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json',
             ],
             'item' => $this->routeGroups->map(function ($routes, $groupName) {

+ 1 - 1
tests/Fixtures/collection.json

@@ -1 +1 @@
-{"variables":[],"info":{"name":"","_postman_id":"","description":"","schema":"https:\/\/schema.getpostman.com\/json\/collection\/v2.0.0\/collection.json"},"item":[{"name":"Group A","description":"","item":[{"name":"Example title.","request":{"url":"http:\/\/localhost\/api\/test","method":"GET","body":{"mode":"formdata","formdata":[]},"description":"This will be the long description.\nIt can also be multiple lines long.","response":[]}},{"name":"http:\/\/localhost\/api\/responseTag","request":{"url":"http:\/\/localhost\/api\/responseTag","method":"POST","body":{"mode":"formdata","formdata":[]},"description":"","response":[]}}]}]}
+{"variables":[],"info":{"name":"Laravel API","_postman_id":"","description":"","schema":"https:\/\/schema.getpostman.com\/json\/collection\/v2.0.0\/collection.json"},"item":[{"name":"Group A","description":"","item":[{"name":"Example title.","request":{"url":"http:\/\/localhost\/api\/test","method":"GET","body":{"mode":"formdata","formdata":[]},"description":"This will be the long description.\nIt can also be multiple lines long.","response":[]}},{"name":"http:\/\/localhost\/api\/responseTag","request":{"url":"http:\/\/localhost\/api\/responseTag","method":"POST","body":{"mode":"formdata","formdata":[]},"description":"","response":[]}}]}]}