Explorar o código

Update the example custom file if there were no custom endpoints

shalvah %!s(int64=3) %!d(string=hai) anos
pai
achega
8f7e7bde1a

+ 13 - 1
src/Commands/GenerateDocumentation.php

@@ -42,11 +42,17 @@ class GenerateDocumentation extends Command
 
         $groupedEndpointsInstance = $groupedEndpointsFactory->make($this, $routeMatcher);
 
+        $userDefinedEndpoints = Camel::loadUserDefinedEndpoints(Camel::$camelDir);
         $groupedEndpoints = $this->mergeUserDefinedEndpoints(
             $groupedEndpointsInstance->get(),
-            Camel::loadUserDefinedEndpoints(Camel::$camelDir)
+            $userDefinedEndpoints
         );
 
+        if (!count($userDefinedEndpoints)) {
+            // Update the example custom file if there were no custom endpoints
+            $this->writeExampleCustomEndpoint();
+        }
+
         $writer = new Writer($this->docConfig);
         $writer->writeDocs($groupedEndpoints);
 
@@ -119,6 +125,12 @@ class GenerateDocumentation extends Command
         return $groupedEndpoints;
     }
 
+    protected function writeExampleCustomEndpoint(): void
+    {
+        // We add an example to guide users in case they need to add a custom endpoint.
+        copy(__DIR__ . '/../../resources/example_custom_endpoint.yaml', Camel::$camelDir . '/custom.0.yaml');
+    }
+
     protected function upgradeConfigFileIfNeeded(): void
     {
         $upgrader = Upgrader::ofConfigFile('config/scribe.php', __DIR__ . '/../../config/scribe.php')

+ 0 - 9
src/GroupedEndpoints/GroupedEndpointsFromApp.php

@@ -75,7 +75,6 @@ class GroupedEndpointsFromApp implements GroupedEndpointsContract
         $endpoints = $this->extractEndpointsInfoFromLaravelApp($routes, $cachedEndpoints, $latestEndpointsData, $groups);
         $groupedEndpoints = Camel::groupEndpoints($endpoints, $this->endpointGroupIndexes);
         $this->writeEndpointsToDisk($groupedEndpoints);
-        $this->writeExampleCustomEndpoint();
         $groupedEndpoints = Camel::prepareGroupedEndpointsForOutput($groupedEndpoints);
         return $groupedEndpoints;
     }
@@ -272,14 +271,6 @@ class GroupedEndpointsFromApp implements GroupedEndpointsContract
         return $shouldIgnoreMethod;
     }
 
-    protected function writeExampleCustomEndpoint(): void
-    {
-        // We add an example to guide users in case they need to add a custom endpoint.
-        if (!file_exists(static::$camelDir . '/custom.0.yaml')) {
-            copy(__DIR__ . '/../../resources/example_custom_endpoint.yaml', static::$camelDir . '/custom.0.yaml');
-        }
-    }
-
     protected function extractAndWriteApiDetailsToDisk(): void
     {
         $apiDetails = new ApiDetails($this->docConfig, !$this->command->option('force'));