Browse Source

Merge remote-tracking branch 'origin/master'

shalvah 4 years ago
parent
commit
3d7f089935

+ 4 - 0
CHANGELOG.md

@@ -12,6 +12,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 
 ### Removed
 
+## 1.1.0 (Monday, 1 June, 2020)
+### Modified
+- Added ability to set postman base_url independently (https://github.com/knuckleswtf/scribe/pull/31)
+
 ## 1.0.3 (Monday, 25 May, 2020)
 ### Modified
 - Updated dependencies (https://github.com/knuckleswtf/scribe/pull/26)

+ 7 - 1
config/scribe.php

@@ -99,7 +99,7 @@ INTRO
     ],
 
     /*
-     * The base URL to be used in examples and the Postman collection.
+     * The base URL to be used in examples.
      * If this is null, Scribe will use the value of config('app.url').
      */
     'base_url' => null,
@@ -122,6 +122,12 @@ INTRO
          */
         'enabled' => true,
 
+        /*
+         * The base URL to be used in the Postman collection.
+         * If this is null, Scribe will use the value of base_url set above.
+         */
+        'base_url' => null,
+
         /*
          * The description for the exported Postman collection.
          */

+ 3 - 1
docs/config.md

@@ -30,7 +30,7 @@ Settings for the `laravel` type output.
 - `middleware`: List of middleware to be attached to the documentation endpoint (if `add_routes` is true).
 
 ### `base_url`
-The base URL to be used in examples and the Postman collection. By default, this will be the value of `config('app.url')`.
+The base URL to be used in examples. By default, this will be the value of `config('app.url')`.
 
 ### `intro_text`
 The text to place in the "Introduction" section. Markdown and HTML are supported.
@@ -63,6 +63,8 @@ For `static` output, the collection will be created in `public/docs/collection.j
 
 - `description`: The description for the generated Postman collection.
 
+- `base_url`: The base URL to be used in the Postman collection. If this is null, Scribe will use the value of [`base_url`](#base_url) set above.
+
 - `auth`: The "Auth" section that should appear in the postman collection. See the [Postman schema docs](https://schema.getpostman.com/json/collection/v2.0.0/docs/index.html) for more information.
 
 ## Extraction settings

+ 1 - 1
docs/documenting/documenting-endpoint-body-parameters.md

@@ -60,7 +60,7 @@ public function createPost(CreatePostRequest $request)
 ```
 
 ### Handling array and object parameters
-Sometimes you have body parameters that are arrays ir ibjects. To handle them in `@bodyparam`, Scribe follows Laravel's convention:
+Sometimes you have body parameters that are arrays or objects. To handle them in `@bodyparam`, Scribe follows Laravel's convention:
 - For arrays: use `<name>.*`
 - For objects: use `<name>.<key>`.
 

+ 1 - 1
docs/documenting/documenting-endpoint-responses.md

@@ -303,7 +303,7 @@ If you want specific relations to be loaded with your model when instantiating v
 ```php
 /**
  * @apiResourceCollection App\Resources\UserCollection
- * @apiResourceModel App\Models\User relations=teacher,classmates
+ * @apiResourceModel App\Models\User with=teacher,classmates
  */
 ```
 

+ 10 - 4
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();
@@ -400,14 +406,14 @@ class Writer
     protected function fetchLastTimeWeModifiedFilesFromTrackingFile()
     {
         if (file_exists($this->fileModificationTimesFile)) {
-            $lastTimesWeModifiedTheseFiles = explode("\n", file_get_contents($this->fileModificationTimesFile));
+            $lastTimesWeModifiedTheseFiles = explode("\n", trim(file_get_contents($this->fileModificationTimesFile)));
             // First two lines are comments
             array_shift($lastTimesWeModifiedTheseFiles);
             array_shift($lastTimesWeModifiedTheseFiles);
             $this->lastTimesWeModifiedTheseFiles = collect($lastTimesWeModifiedTheseFiles)
                 ->mapWithKeys(function ($line) {
-                    [$filePath, $mtime] = explode("=", $line);
-                    return [$filePath => $mtime];
+                    [$filePath, $modificationTime] = explode("=", $line);
+                    return [$filePath => $modificationTime];
                 })->toArray();
         }
     }

+ 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');