Просмотр исходного кода

feat(config): ability to set postman base_url independently

Martin Hsia 5 лет назад
Родитель
Сommit
ac8564f1e7
3 измененных файлов с 15 добавлено и 2 удалено
  1. 7 0
      config/scribe.php
  2. 7 1
      src/Writing/Writer.php
  3. 1 1
      tests/GenerateDocumentationTest.php

+ 7 - 0
config/scribe.php

@@ -122,6 +122,13 @@ INTRO
          */
         'enabled' => true,
 
+        /*
+         * The base URL to be used in the Postman collection.
+         * This will override the base_url settings above only for Postman.
+         * If this is null, Scribe will use the value of config('app.url').
+         */
+        'base_url' => null,
+
         /*
          * The description for the exported Postman collection.
          */

+ 7 - 1
src/Writing/Writer.php

@@ -23,6 +23,11 @@ class Writer
      */
     private $baseUrl;
 
+    /**
+     * @var string
+     */
+    private $postmanBaseUrl;
+
     /**
      * @var bool
      */
@@ -73,6 +78,7 @@ class Writer
         // If no config is injected, pull from global. Makes testing easier.
         $this->config = $config ?: new DocumentationConfig(config('scribe'));
         $this->baseUrl = $this->config->get('base_url') ?? config('app.url');
+        $this->postmanBaseUrl = $this->config->get('postman.base_url') ?? $this->baseUrl;
         $this->shouldOverwrite = $shouldOverwrite;
         $this->shouldGeneratePostmanCollection = $this->config->get('postman.enabled', false);
         $this->pastel = new Pastel();
@@ -180,7 +186,7 @@ class Writer
         /** @var PostmanCollectionWriter $writer */
         $writer = app()->makeWith(
             PostmanCollectionWriter::class,
-            ['routeGroups' => $routes, 'baseUrl' => $this->baseUrl]
+            ['routeGroups' => $routes, 'baseUrl' => $this->postmanBaseUrl]
         );
 
         return $writer->makePostmanCollection();

+ 1 - 1
tests/GenerateDocumentationTest.php

@@ -264,7 +264,7 @@ class GenerateDocumentationTest extends TestCase
     /** @test */
     public function generated_postman_collection_can_have_custom_url()
     {
-        Config::set('scribe.base_url', 'http://yourapp.app');
+        Config::set('scribe.postman.base_url', 'http://yourapp.app');
         RouteFacade::get('/api/test', TestController::class . '@withEndpointDescription');
         RouteFacade::post('/api/responseTag', TestController::class . '@withResponseTag');