diff --git a/src/GroupedEndpoints/GroupedEndpointsFromApp.php b/src/GroupedEndpoints/GroupedEndpointsFromApp.php index b05fc49a..e234d974 100644 --- a/src/GroupedEndpoints/GroupedEndpointsFromApp.php +++ b/src/GroupedEndpoints/GroupedEndpointsFromApp.php @@ -213,7 +213,9 @@ protected function writeEndpointsToDisk(array $grouped): void && 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++; } diff --git a/tests/Fixtures/.scribe/endpoints/0.yaml b/tests/Fixtures/.scribe/endpoints/00.yaml similarity index 100% rename from tests/Fixtures/.scribe/endpoints/0.yaml rename to tests/Fixtures/.scribe/endpoints/00.yaml diff --git a/tests/GenerateDocumentationTest.php b/tests/GenerateDocumentationTest.php index 18220aed..373cc035 100644 --- a/tests/GenerateDocumentationTest.php +++ b/tests/GenerateDocumentationTest.php @@ -264,7 +264,7 @@ public function can_append_custom_http_headers() ]); $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 @@ public function sorts_group_naturally() 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 @@ public function will_not_overwrite_manually_modified_content_unless_force_flag_i $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 @@ public function generates_correct_url_params_from_resource_routes_and_field_bind $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 @@ public function respects_endpoints_and_group_sort_order() $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 @@ public function will_auto_set_content_type_to_multipart_if_file_params_are_prese $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']);