Bläddra i källkod

Don't crash on unrecognized validation rule formats

shalvah 4 år sedan
förälder
incheckning
c86ea65e90

+ 5 - 3
camel/Output/OutputEndpointData.php

@@ -106,8 +106,10 @@ class OutputEndpointData extends BaseDTO
         [$files, $regularParameters] = collect($this->cleanBodyParameters)
             ->partition(
                 function ($example) {
-                    return $example instanceof UploadedFile
-                        || (is_array($example) && ($example[0] ?? null) instanceof UploadedFile);
+                    // We'll only check two levels: a file, or an array of files
+                    return is_array($example) && isset($example[0])
+                        ? $example[0] instanceof UploadedFile
+                        : $example instanceof UploadedFile;
                 }
             );
         if (count($files)) {
@@ -142,7 +144,7 @@ class OutputEndpointData extends BaseDTO
 
     public function endpointId(): string
     {
-        return $this->httpMethods[0].str_replace(['/', '?', '{', '}', ':'], '-', $this->uri);
+        return $this->httpMethods[0] . str_replace(['/', '?', '{', '}', ':'], '-', $this->uri);
     }
 
     public function hasResponses(): bool

+ 4 - 0
src/Extracting/ParsesValidationRules.php

@@ -143,6 +143,10 @@ trait ParsesValidationRules
      */
     protected function parseRule($rule, array &$parameterData, bool $independentOnly, array $allParameters = []): bool
     {
+        if (!(is_string($rule) || $rule instanceof Rule)) {
+            return true;
+        }
+
         // Convert string rules into rule + arguments (eg "in:1,2" becomes ["in", ["1", "2"]])
         $parsedRule = $this->parseStringRuleIntoRuleAndArguments($rule);
         [$rule, $arguments] = $parsedRule;

+ 1 - 0
src/Extracting/Strategies/BodyParameters/GetFromBodyParamTag.php

@@ -75,6 +75,7 @@ class GetFromBodyParamTag extends Strategy
 
             $type = $this->normalizeTypeName($type);
             [$description, $example] = $this->parseExampleFromParamDescription($description, $type);
+
             $example = is_null($example) && !$this->shouldExcludeExample($tagContent)
                 ? $this->generateDummyValue($type)
                 : $example;