Browse Source

Rename key `response` to `responses` in parsedRoute

shalvah 5 years ago
parent
commit
da861ff464

+ 1 - 13
resources/views/partials/route.blade.php

@@ -17,8 +17,7 @@
 @endforeach
 
 @if(in_array('GET',$route['methods']) || (isset($route['showresponse']) && $route['showresponse']))
-@if(is_array($route['response']))
-@foreach($route['response'] as $response)
+@foreach($route['responses'] as $response)
 > Example response ({{$response['status']}}):
 
 ```json
@@ -29,17 +28,6 @@
 @endif
 ```
 @endforeach
-@else
-> Example response:
-
-```json
-@if(is_object($route['response']) || is_array($route['response']))
-{!! json_encode($route['response'], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) !!}
-@else
-{!! json_encode(json_decode($route['response']), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) !!}
-@endif
-```
-@endif
 @endif
 
 ### HTTP Request

+ 0 - 1
src/Strategies/Responses/UseResponseTag.php

@@ -61,7 +61,6 @@ class UseResponseTag extends Strategy
             return ['content' => $content, 'status' => (int) $status];
         }, $responseTags);
 
-        // Convert responses to [200 => 'response', 401 => 'response']
         return $responses;
     }
 }

+ 1 - 1
src/Tools/Generator.php

@@ -75,7 +75,7 @@ class Generator
         $parsedRoute['cleanBodyParameters'] = $this->cleanParams($bodyParameters);
 
         $responses = $this->fetchResponses($controller, $method, $route, $routeRules, $parsedRoute);
-        $parsedRoute['response'] = $responses;
+        $parsedRoute['responses'] = $responses;
         $parsedRoute['showresponse'] = ! empty($responses);
 
         $parsedRoute['headers'] = $routeRules['headers'] ?? [];

+ 3 - 3
tests/Unit/GeneratorPluginSystemTestCase.php

@@ -66,12 +66,12 @@ class GeneratorPluginSystemTestCase extends LaravelGeneratorTest
         $parsed = $generator->processRoute($route);
 
         $this->assertTrue($parsed['showresponse']);
-        $this->assertCount(2, $parsed['response']);
-        $first = array_shift($parsed['response']);
+        $this->assertCount(2, $parsed['responses']);
+        $first = array_shift($parsed['responses']);
         $this->assertTrue(is_array($first));
         $this->assertEquals(200, $first['status']);
         $this->assertEquals('dummy', $first['content']);
-        $second = array_shift($parsed['response']);
+        $second = array_shift($parsed['responses']);
         $this->assertTrue(is_array($second));
         $this->assertEquals(400, $second['status']);
         $this->assertEquals('dummy2', $second['content']);

+ 30 - 30
tests/Unit/GeneratorTestCase.php

@@ -399,7 +399,7 @@ abstract class GeneratorTestCase extends TestCase
         $generator = new Generator(new DocumentationConfig($config));
         $parsed = $this->generator->processRoute($route);
 
-        $response = Arr::first($parsed['response']);
+        $response = Arr::first($parsed['responses']);
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
         $this->assertTrue($parsed['showresponse']);
@@ -422,7 +422,7 @@ abstract class GeneratorTestCase extends TestCase
         $generator = new Generator(new DocumentationConfig($config));
         $parsed = $this->generator->processRoute($route);
 
-        $response = Arr::first($parsed['response']);
+        $response = Arr::first($parsed['responses']);
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
         $this->assertTrue($parsed['showresponse']);
@@ -452,7 +452,7 @@ abstract class GeneratorTestCase extends TestCase
         $generator = new Generator(new DocumentationConfig($config));
         $parsed = $this->generator->processRoute($route);
 
-        $response = Arr::first($parsed['response']);
+        $response = Arr::first($parsed['responses']);
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
         $this->assertTrue($parsed['showresponse']);
@@ -484,7 +484,7 @@ abstract class GeneratorTestCase extends TestCase
     {
         $route = $this->createRoute('POST', '/responseTag', 'withResponseTag');
         $parsed = $this->generator->processRoute($route);
-        $response = Arr::first($parsed['response']);
+        $response = Arr::first($parsed['responses']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -505,7 +505,7 @@ abstract class GeneratorTestCase extends TestCase
     {
         $route = $this->createRoute('POST', '/responseTag', 'withResponseTagAndStatusCode');
         $parsed = $this->generator->processRoute($route);
-        $response = Arr::first($parsed['response']);
+        $response = Arr::first($parsed['responses']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -526,20 +526,20 @@ abstract class GeneratorTestCase extends TestCase
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
         $this->assertTrue($parsed['showresponse']);
-        $this->assertTrue(is_array($parsed['response'][0]));
-        $this->assertEquals(200, $parsed['response'][0]['status']);
+        $this->assertTrue(is_array($parsed['responses'][0]));
+        $this->assertEquals(200, $parsed['responses'][0]['status']);
         $this->assertArraySubset([
             'id' => 4,
             'name' => 'banana',
             'color' => 'red',
             'weight' => '1 kg',
             'delicious' => true,
-        ], json_decode($parsed['response'][0]['content'], true));
-        $this->assertTrue(is_array($parsed['response'][1]));
-        $this->assertEquals(401, $parsed['response'][1]['status']);
+        ], json_decode($parsed['responses'][0]['content'], true));
+        $this->assertTrue(is_array($parsed['responses'][1]));
+        $this->assertEquals(401, $parsed['responses'][1]['status']);
         $this->assertArraySubset([
             'message' => 'Unauthorized',
-        ], json_decode($parsed['response'][1]['content'], true));
+        ], json_decode($parsed['responses'][1]['content'], true));
     }
 
     /**
@@ -554,7 +554,7 @@ abstract class GeneratorTestCase extends TestCase
         config(['apidoc.fractal.serializer' => $serializer]);
         $route = $this->createRoute('GET', '/transformerTag', 'transformerTag');
         $parsed = $this->generator->processRoute($route);
-        $response = Arr::first($parsed['response']);
+        $response = Arr::first($parsed['responses']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -572,7 +572,7 @@ abstract class GeneratorTestCase extends TestCase
     {
         $route = $this->createRoute('GET', '/transformerTagWithModel', 'transformerTagWithModel');
         $parsed = $this->generator->processRoute($route);
-        $response = Arr::first($parsed['response']);
+        $response = Arr::first($parsed['responses']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -590,7 +590,7 @@ abstract class GeneratorTestCase extends TestCase
     {
         $route = $this->createRoute('GET', '/transformerTagWithStatusCode', 'transformerTagWithStatusCode');
         $parsed = $this->generator->processRoute($route);
-        $response = Arr::first($parsed['response']);
+        $response = Arr::first($parsed['responses']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -608,7 +608,7 @@ abstract class GeneratorTestCase extends TestCase
     {
         $route = $this->createRoute('GET', '/transformerCollectionTag', 'transformerCollectionTag');
         $parsed = $this->generator->processRoute($route);
-        $response = Arr::first($parsed['response']);
+        $response = Arr::first($parsed['responses']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -627,7 +627,7 @@ abstract class GeneratorTestCase extends TestCase
     {
         $route = $this->createRoute('GET', '/transformerCollectionTagWithModel', 'transformerCollectionTagWithModel');
         $parsed = $this->generator->processRoute($route);
-        $response = Arr::first($parsed['response']);
+        $response = Arr::first($parsed['responses']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -656,7 +656,7 @@ abstract class GeneratorTestCase extends TestCase
             ],
         ];
         $parsed = $this->generator->processRoute($route, $rules);
-        $response = Arr::first($parsed['response']);
+        $response = Arr::first($parsed['responses']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -683,7 +683,7 @@ abstract class GeneratorTestCase extends TestCase
             ],
         ];
         $parsed = $this->generator->processRoute($route, $rules);
-        $response = json_decode(Arr::first($parsed['response'])['content'], true);
+        $response = json_decode(Arr::first($parsed['responses'])['content'], true);
         $originalValue = $response['app.env'];
 
         $now = time();
@@ -696,7 +696,7 @@ abstract class GeneratorTestCase extends TestCase
             ],
         ];
         $parsed = $this->generator->processRoute($route, $rules);
-        $response = json_decode(Arr::first($parsed['response'])['content'], true);
+        $response = json_decode(Arr::first($parsed['responses'])['content'], true);
         $newValue = $response['app.env'];
         $this->assertEquals($now, $newValue);
         $this->assertNotEquals($originalValue, $newValue);
@@ -712,7 +712,7 @@ abstract class GeneratorTestCase extends TestCase
             ],
         ];
         $parsed = $this->generator->processRoute($route, $rules);
-        $response = json_decode(Arr::first($parsed['response'])['content'], true);
+        $response = json_decode(Arr::first($parsed['responses'])['content'], true);
         $this->assertEquals(4, $response['param']);
     }
 
@@ -727,7 +727,7 @@ abstract class GeneratorTestCase extends TestCase
             ],
         ];
         $parsed = $this->generator->processRoute($route, $rules);
-        $response = json_decode(Arr::first($parsed['response'])['content'], true);
+        $response = json_decode(Arr::first($parsed['responses'])['content'], true);
         $this->assertEquals(4, $response['param']);
         $this->assertNotNull($response['param2']);
         $this->assertEquals(1, $response['param3']);
@@ -744,7 +744,7 @@ abstract class GeneratorTestCase extends TestCase
 
         $route = $this->createRoute('GET', '/responseFileTag', 'responseFileTag');
         $parsed = $this->generator->processRoute($route);
-        $response = Arr::first($parsed['response']);
+        $response = Arr::first($parsed['responses']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -769,7 +769,7 @@ abstract class GeneratorTestCase extends TestCase
 
         $route = $this->createRoute('GET', '/responseFileTagAndCustomJson', 'responseFileTagAndCustomJson');
         $parsed = $this->generator->processRoute($route);
-        $response = Arr::first($parsed['response']);
+        $response = Arr::first($parsed['responses']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
@@ -801,16 +801,16 @@ abstract class GeneratorTestCase extends TestCase
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
         $this->assertTrue($parsed['showresponse']);
-        $this->assertTrue(is_array($parsed['response'][0]));
-        $this->assertEquals(200, $parsed['response'][0]['status']);
+        $this->assertTrue(is_array($parsed['responses'][0]));
+        $this->assertEquals(200, $parsed['responses'][0]['status']);
         $this->assertSame(
-            $parsed['response'][0]['content'],
+            $parsed['responses'][0]['content'],
             $successFixtureFileJson
         );
-        $this->assertTrue(is_array($parsed['response'][1]));
-        $this->assertEquals(401, $parsed['response'][1]['status']);
+        $this->assertTrue(is_array($parsed['responses'][1]));
+        $this->assertEquals(401, $parsed['responses'][1]['status']);
         $this->assertSame(
-            $parsed['response'][1]['content'],
+            $parsed['responses'][1]['content'],
             $errorFixtureFileJson
         );
 
@@ -865,7 +865,7 @@ abstract class GeneratorTestCase extends TestCase
             ],
         ];
         $parsed = $this->generator->processRoute($route, $rules);
-        $response = Arr::first($parsed['response']);
+        $response = Arr::first($parsed['responses']);
 
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);