Skip to content

Commit

Permalink
Merge pull request #71 from LibreCodeCoop/fix-pattern-when-dont-have-bar
Browse files Browse the repository at this point in the history
Change to accept regex without /
  • Loading branch information
byjg authored Oct 5, 2021
2 parents c8cf925 + 06ef69b commit 57c86fc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Base/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ protected function matchString($name, $schemaArray, $body, $type)

private function checkPattern($name, $body, $pattern)
{
$pattern = '/' . rtrim(ltrim($pattern, '/'), '/') . '/';
$isSuccess = (bool) preg_match($pattern, $body, $matches);

if (!$isSuccess) {
throw new NotMatchedException("Value '$body' in '$name' not matched in pattern. ", $this->structure);
}
}


/**
* @param string $name
* @param array $schemaArray
Expand Down
2 changes: 1 addition & 1 deletion tests/example/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@
"type": "string",
"format": "date",
"example": "2020-01-28",
"pattern": "/^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\\d|3[0-1])$/"
"pattern": "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\\d|3[0-1])$"
},
"age": {
"type": "string",
Expand Down

0 comments on commit 57c86fc

Please sign in to comment.