Explorar el Código

Fix #68: Properly set examples for URL parameters with regexes

shalvah hace 4 años
padre
commit
7da49f1bb9
Se han modificado 1 ficheros con 14 adiciones y 15 borrados
  1. 14 15
      src/Extracting/Strategies/UrlParameters/GetFromLaravelAPI.php

+ 14 - 15
src/Extracting/Strategies/UrlParameters/GetFromLaravelAPI.php

@@ -20,21 +20,20 @@ class GetFromLaravelAPI extends Strategy
         $parameters = [];
 
         $path = $alreadyExtractedData['uri'];
-        preg_match_all('/\{(\w+\??)}/', $path, $matches);
-
-        if (!empty($matches[1])) {
-            foreach ($matches[1] as $match) {
-                $optional = Str::endsWith($match, '?');
-                $name = rtrim($match, '?');
-                $type = 'string';
-                $parameters[$name] = [
-                    'name' => $name,
-                    'description' => '',
-                    'required' => !$optional,
-                    'value' => $this->generateDummyValue($type),
-                    'type' => $type,
-                ];
-            }
+        preg_match_all('#\{([^/]+?)\}#', $path, $matches);
+
+        foreach ($matches[1] as $match) {
+            $optional = Str::endsWith($match, '?');
+            $name = rtrim($match, '?');
+            $name = preg_replace('/:.+/', '', $name); // remove any specified regex pattern
+            $type = 'string';
+            $parameters[$name] = [
+                'name' => $name,
+                'description' => '',
+                'required' => !$optional,
+                'value' => $this->generateDummyValue($type),
+                'type' => $type,
+            ];
         }
 
         return $parameters;