Kaynağa Gözat

Implement Try It Out functionality

shalvah 4 yıl önce
ebeveyn
işleme
1cddb828d3
2 değiştirilmiş dosya ile 16 ekleme ve 12 silme
  1. 8 1
      config/scribe.php
  2. 8 11
      tests/GenerateDocumentationTest.php

+ 8 - 1
config/scribe.php

@@ -41,6 +41,12 @@ return [
         'middleware' => [],
     ],
 
+    'output' => [
+        /**
+         * Add a Try It Out button to your endpoints so consumers can test endpoints right from their browser.
+         */
+        'interactive' => true,
+    ],
     /*
      * How is your API authenticated? This information will be used in the displayed docs, generated examples and response calls.
      */
@@ -65,7 +71,7 @@ return [
         /*
          * The name of the parameter (eg token, key, apiKey) or header (eg Authorization, Api-Key).
          */
-        'name' => 'token',
+        'name' => 'key',
 
         /*
          * The value of the parameter to be used by Scribe to authenticate response calls.
@@ -319,6 +325,7 @@ INTRO
             \Knuckles\Scribe\Extracting\Strategies\Metadata\GetFromDocBlocks::class,
         ],
         'urlParameters' => [
+            \Knuckles\Scribe\Extracting\Strategies\UrlParameters\GetFromLaravelAPI::class,
             \Knuckles\Scribe\Extracting\Strategies\UrlParameters\GetFromUrlParamTag::class,
         ],
         'queryParameters' => [

+ 8 - 11
tests/GenerateDocumentationTest.php

@@ -2,10 +2,7 @@
 
 namespace Knuckles\Scribe\Tests;
 
-use Illuminate\Support\Facades\App;
-use Illuminate\Support\Facades\Config;
 use Illuminate\Support\Facades\Route as RouteFacade;
-use Illuminate\Support\Str;
 use Knuckles\Scribe\ScribeServiceProvider;
 use Knuckles\Scribe\Tests\Fixtures\TestController;
 use Knuckles\Scribe\Tests\Fixtures\TestGroupController;
@@ -15,7 +12,6 @@ use Knuckles\Scribe\Tests\Fixtures\TestResourceController;
 use Knuckles\Scribe\Tests\Fixtures\TestUser;
 use Knuckles\Scribe\Tools\Utils;
 use Orchestra\Testbench\TestCase;
-use ReflectionException;
 use Symfony\Component\Yaml\Yaml;
 
 class GenerateDocumentationTest extends TestCase
@@ -39,8 +35,8 @@ class GenerateDocumentationTest extends TestCase
 
     public function tearDown(): void
     {
-      //  Utils::deleteDirectoryAndContents('/public/docs');
-      //  Utils::deleteDirectoryAndContents('/resources/docs');
+      Utils::deleteDirectoryAndContents('/public/docs');
+      Utils::deleteDirectoryAndContents('/resources/docs');
     }
 
     /**
@@ -239,6 +235,7 @@ class GenerateDocumentationTest extends TestCase
         // We want to have the same values for params each time
         config(['scribe.faker_seed' => 1234]);
         config(['scribe.title' => 'GREAT API!']);
+        config(['scribe.auth.enabled' => true]);
         config(['scribe.routes.0.match.prefixes' => ['api/*']]);
         config(['scribe.postman.overrides' => [
             'info.version' => '3.9.9',
@@ -253,11 +250,11 @@ class GenerateDocumentationTest extends TestCase
 
         $this->artisan('scribe:generate');
 
-       //  $generatedCollection = json_decode(file_get_contents(__DIR__ . '/../public/docs/collection.json'), true);
-       //  // The Postman ID varies from call to call; erase it to make the test data reproducible.
-       //  $generatedCollection['info']['_postman_id'] = '';
-       //  $fixtureCollection = json_decode(file_get_contents(__DIR__ . '/Fixtures/collection.json'), true);
-       //  $this->assertEquals($fixtureCollection, $generatedCollection);
+       $generatedCollection = json_decode(file_get_contents(__DIR__ . '/../public/docs/collection.json'), true);
+       // The Postman ID varies from call to call; erase it to make the test data reproducible.
+       $generatedCollection['info']['_postman_id'] = '';
+       $fixtureCollection = json_decode(file_get_contents(__DIR__ . '/Fixtures/collection.json'), true);
+       $this->assertEquals($fixtureCollection, $generatedCollection);
     }
 
     /** @test */