Kaynağa Gözat

Sort group filenames numerically (fixes #273)

shalvah 3 yıl önce
ebeveyn
işleme
c77fed23f0

+ 3 - 1
src/GroupedEndpoints/GroupedEndpointsFromApp.php

@@ -213,7 +213,9 @@ class GroupedEndpointsFromApp implements GroupedEndpointsContract
                 && isset(Camel::$groupFileNames[$group['name']])) {
                 $fileName = Camel::$groupFileNames[$group['name']];
             } else {
-                $fileName = "$fileNameIndex.yaml";
+                // Format numbers as two digits so they are sorted properly when retrieving later
+                // (ie "10.yaml" comes after "9.yaml", not after "1.yaml")
+                $fileName = sprintf("%02d.yaml", $fileNameIndex);
                 $fileNameIndex++;
             }
 

+ 0 - 0
tests/Fixtures/.scribe/endpoints/0.yaml → tests/Fixtures/.scribe/endpoints/00.yaml


+ 15 - 15
tests/GenerateDocumentationTest.php

@@ -264,7 +264,7 @@ class GenerateDocumentationTest extends BaseLaravelTest
         ]);
         $this->artisan('scribe:generate');
 
-        $endpointDetails = Yaml::parseFile(__DIR__ . '/../.scribe/endpoints/0.yaml')['endpoints'][0];
+        $endpointDetails = Yaml::parseFile(__DIR__ . '/../.scribe/endpoints/00.yaml')['endpoints'][0];
         $this->assertEquals("customAuthToken", $endpointDetails['headers']["Authorization"]);
         $this->assertEquals("NotSoCustom", $endpointDetails['headers']["Custom-Header"]);
     }
@@ -292,12 +292,12 @@ class GenerateDocumentationTest extends BaseLaravelTest
         config(['scribe.routes.0.match.prefixes' => ['api/*']]);
         $this->artisan('scribe:generate');
 
-        $this->assertFileExists(__DIR__ . '/../.scribe/endpoints/0.yaml');
-        $this->assertFileExists(__DIR__ . '/../.scribe/endpoints/1.yaml');
-        $this->assertFileExists(__DIR__ . '/../.scribe/endpoints/2.yaml');
-        $this->assertEquals('1. Group 1', Yaml::parseFile(__DIR__ . '/../.scribe/endpoints/0.yaml')['name']);
-        $this->assertEquals('2. Group 2', Yaml::parseFile(__DIR__ . '/../.scribe/endpoints/1.yaml')['name']);
-        $this->assertEquals('10. Group 10', Yaml::parseFile(__DIR__ . '/../.scribe/endpoints/2.yaml')['name']);
+        $this->assertFileExists(__DIR__ . '/../.scribe/endpoints/00.yaml');
+        $this->assertFileExists(__DIR__ . '/../.scribe/endpoints/01.yaml');
+        $this->assertFileExists(__DIR__ . '/../.scribe/endpoints/02.yaml');
+        $this->assertEquals('1. Group 1', Yaml::parseFile(__DIR__ . '/../.scribe/endpoints/00.yaml')['name']);
+        $this->assertEquals('2. Group 2', Yaml::parseFile(__DIR__ . '/../.scribe/endpoints/01.yaml')['name']);
+        $this->assertEquals('10. Group 10', Yaml::parseFile(__DIR__ . '/../.scribe/endpoints/02.yaml')['name']);
     }
 
     /** @test */
@@ -324,7 +324,7 @@ class GenerateDocumentationTest extends BaseLaravelTest
         $this->artisan('scribe:generate');
 
         $authFilePath = '.scribe/auth.md';
-        $group1FilePath = '.scribe/endpoints/0.yaml';
+        $group1FilePath = '.scribe/endpoints/00.yaml';
 
         $group = Yaml::parseFile($group1FilePath);
         $this->assertEquals('api/action1', $group['endpoints'][0]['uri']);
@@ -376,9 +376,9 @@ class GenerateDocumentationTest extends BaseLaravelTest
 
         $this->artisan('scribe:generate');
 
-        $groupA = Yaml::parseFile('.scribe/endpoints/0.yaml');
+        $groupA = Yaml::parseFile('.scribe/endpoints/00.yaml');
         $this->assertEquals('providers/{provider_slug}/users/{user_id}/addresses', $groupA['endpoints'][0]['uri']);
-        $groupB = Yaml::parseFile('.scribe/endpoints/1.yaml');
+        $groupB = Yaml::parseFile('.scribe/endpoints/01.yaml');
         $this->assertEquals('providers/{provider_slug}/users/{user_id}/addresses/{uuid}', $groupB['endpoints'][0]['uri']);
     }
 
@@ -452,19 +452,19 @@ class GenerateDocumentationTest extends BaseLaravelTest
         $this->assertEquals("GET api/action2", $expectedEndpoints->getNode(2)->textContent);
 
         // Now swap the endpoints
-        $group = Yaml::parseFile('.scribe/endpoints/0.yaml');
+        $group = Yaml::parseFile('.scribe/endpoints/00.yaml');
         $this->assertEquals('api/action1', $group['endpoints'][0]['uri']);
         $this->assertEquals('api/action1b', $group['endpoints'][1]['uri']);
         $action1 = $group['endpoints'][0];
         $group['endpoints'][0] = $group['endpoints'][1];
         $group['endpoints'][1] = $action1;
-        file_put_contents('.scribe/endpoints/0.yaml', Yaml::dump(
+        file_put_contents('.scribe/endpoints/00.yaml', Yaml::dump(
             $group, 20, 2,
             Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP
         ));
         // And then the groups
-        rename('.scribe/endpoints/0.yaml', '.scribe/endpoints/temp.yaml');
-        rename('.scribe/endpoints/1.yaml', '.scribe/endpoints/0.yaml');
+        rename('.scribe/endpoints/00.yaml', '.scribe/endpoints/temp.yaml');
+        rename('.scribe/endpoints/01.yaml', '.scribe/endpoints/00.yaml');
         rename('.scribe/endpoints/temp.yaml', '.scribe/endpoints/1.yaml');
 
         $this->artisan('scribe:generate');
@@ -500,7 +500,7 @@ class GenerateDocumentationTest extends BaseLaravelTest
 
         $this->artisan('scribe:generate');
 
-        $group = Yaml::parseFile('.scribe/endpoints/0.yaml');
+        $group = Yaml::parseFile('.scribe/endpoints/00.yaml');
         $this->assertEquals('no-file', $group['endpoints'][0]['uri']);
         $this->assertEquals('application/json', $group['endpoints'][0]['headers']['Content-Type']);
         $this->assertEquals('top-level-file', $group['endpoints'][1]['uri']);