Skip to content

Commit

Permalink
Merge pull request #54 from swaggest/update-test-suite
Browse files Browse the repository at this point in the history
update JSON-Schema-Test-Suite, AJV test suite and fix failed tests
  • Loading branch information
vearutop committed Jul 30, 2018
2 parents 87b25f8 + 1228ba8 commit b603aaa
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion spec/ajv
Submodule ajv updated from 2726d2 to 88d57f
25 changes: 22 additions & 3 deletions src/Constraint/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Format
const IRI_REFERENCE = 'iri-reference';
const URI_TEMPLATE = 'uri-template';

public static $strictDateTimeValidation = false;

private static $dateRegexPart = '(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])';
private static $timeRegexPart = '([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)([01][0-9]|2[0-3]):([0-5][0-9]))?';
private static $jsonPointerRegex = '_^(?:/|(?:/[^/#]*)*)$_';
Expand Down Expand Up @@ -75,9 +77,26 @@ public static function validationError($format, $data)

public static function dateTimeError($data)
{
return preg_match('/^' . self::$dateRegexPart . 'T' . self::$timeRegexPart . '$/i', $data)
? null
: 'Invalid date-time: ' . $data;
if (!preg_match('/^' . self::$dateRegexPart . 'T' . self::$timeRegexPart . '$/i', $data)) {
return 'Invalid date-time format: ' . $data;
}

if (self::$strictDateTimeValidation) {
$dt = date_create($data);
if ($dt === false) {
return 'Failed to parse date-time: ' . $data;
}
$isLeapSecond = '6' === $data[17] && (
0 === strpos(substr($data, 5, 5), '12-31') ||
0 === strpos(substr($data, 5, 5), '06-30')
);
if (!$isLeapSecond &&
0 !== stripos($dt->format(DATE_RFC3339), substr($data, 0, 19))) {
return 'Invalid date-time value: ' . $data;
}
}

return null;
}

public static function regexError($data)
Expand Down
14 changes: 9 additions & 5 deletions src/Constraint/UniqueItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ public static function isValid(array $data)
foreach ($data as $value) {
if (is_array($value) || $value instanceof \stdClass) {
$value = json_encode($value);
}
if (is_bool($value)) {
$value = '_______BOOL' . $value;
}
if ($value instanceof ObjectItemContract) {
} elseif (is_bool($value)) {
$value = '_B' . $value;
} elseif (is_string($value)) {
$value = '_S' . $value;
} elseif (is_int($value)) {
$value = '_I' . $value;
} elseif (is_float($value)) {
$value = '_F' . $value;
} elseif ($value instanceof ObjectItemContract) {
$value = json_encode($value);
}
$tmp = &$index[$value];
Expand Down
3 changes: 3 additions & 0 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,9 @@ public function process($data, Context $options, $path = '#', $result = null)
}

if ($this->contentEncoding !== null || $this->contentMediaType !== null) {
if ($import && !is_string($data)) {
return $result;
}
$result = $this->processContent($data, $options, $path);
}

Expand Down
3 changes: 2 additions & 1 deletion tests/src/PHPUnit/Spec/SchemaTestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Swaggest\JsonSchema\Tests\PHPUnit\Spec;

use Swaggest\JsonSchema\Constraint\Format;
use Swaggest\JsonSchema\Context;
use Swaggest\JsonSchema\InvalidValue;
use Swaggest\JsonSchema\Schema;
Expand Down Expand Up @@ -164,7 +165,7 @@ protected function makeOptions($version)
*/
protected function runSpecTest($schemaData, $data, $isValid, $name, $version)
{

Format::$strictDateTimeValidation = true;
$actualValid = true;
$error = '';
try {
Expand Down

0 comments on commit b603aaa

Please sign in to comment.