Skip to content

Commit

Permalink
Don't crash on unrecognized validation rule formats
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Jun 8, 2021
1 parent badae47 commit c86ea65
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions camel/Output/OutputEndpointData.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ public function __construct(array $parameters = [])
[$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)) {
Expand Down Expand Up @@ -142,7 +144,7 @@ public static function fromExtractedEndpointArray(array $endpoint): OutputEndpoi

public function endpointId(): string
{
return $this->httpMethods[0].str_replace(['/', '?', '{', '}', ':'], '-', $this->uri);
return $this->httpMethods[0] . str_replace(['/', '?', '{', '}', ':'], '-', $this->uri);
}

public function hasResponses(): bool
Expand Down
4 changes: 4 additions & 0 deletions src/Extracting/ParsesValidationRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ protected function normaliseRules(array $rules): array
*/
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function getBodyParametersFromDocBlock(array $tags): array

$type = $this->normalizeTypeName($type);
[$description, $example] = $this->parseExampleFromParamDescription($description, $type);

$example = is_null($example) && !$this->shouldExcludeExample($tagContent)
? $this->generateDummyValue($type)
: $example;
Expand Down

0 comments on commit c86ea65

Please sign in to comment.