462 Commits

Author SHA1 Message Date
Erayd
d283e11b6e Add a path to the default internal URI (#459) (#460)
Fixes #458.
5.2.6
2017-10-21 08:15:38 -05:00
Erayd
0d4fda8efd Don't add a file:// prefix to URI that already have a scheme (#455) (#457)
Some URI types do not pass validation against \FILTER_VAR_URL (e.g.
phar://), but are still valid and still have a scheme. This patch
catches those situations via a simple regex.
5.2.5
2017-10-10 08:22:37 -05:00
Erayd
7ccb0e67ea [BUGFIX] Don't resolve a schema id against itself (#452) (#453)
* Don't resolve a schema id against itself

* Add test for double-resolve bugfix
5.2.4 5.2.3
2017-10-04 22:57:36 +02:00
Erayd
b80053b620 Backports for 5.2.2 (Part 3) (#450)
* Update php-csfixer rules to address problem in 2.7 & new multiline rule (#449)

* Update php-csfixer rules to address problem in 2.7 & new multiline rule

 * yoda_style in 2.7 is dangerous and may result in logic errors. In
 some cases, it also results in invalid syntax.

 * multiline comments prefixed with // now seem to be misaligned, and
 this cannot be disabled, so have changed the relevant comment.

* PHP-5.3 is not available on trusty, so explicitly specify precise for 5.3

* Add proper recursive handling for $ref resolution base (#448)

Fixes #447

Note that this patch does not check whether a given container is
actually a schema when recursing into it. In most cases this will
not matter, however it does mean that in some edge cases it will
attempt to resolve a `$ref` in a context where ref is actually not
part of the spec. Limiting resolution to schema-context containers
is outside the scope of this patch, but can be added later.
5.2.2
2017-10-03 02:49:49 +02:00
Erayd
36ed4d935f Added property name in draft-3 required error (#432) (#433)
Backport modifications:
 * Change error syntax to use the old pre-6.0.0 API
2017-06-23 06:43:36 -05:00
Erayd
2a4203948b Backports for 5.2.2 (#431)
* Remove PHPDocumentor & change travis platform for hhvm tests (#429)

* Remove dev-time dependency on phpdocumentor due to resolution headaches

* Switch distro for hhvm testing to trusty (precise now unsupported)

* Bugfix for #424 - add '?' for query string (#425)

Note that this bugfix will cause empty query strings to be dropped (e.g.
http://example.com?#blue becomes http://example.com#blue). This is
because the '?' character is deliberately not captured as part of the
query string, and the testsuite expects to be able to pass an empty
query string and *not* have the '?' added for that case.
2017-06-05 15:17:19 -05:00
Erayd
429be236f2 Backports for 5.2.1 (#413)
* Split $objectDefinition into $schema and $properties (#411)

Object validation attempts to use a single variable to store both the
object definition, and its properties. This causes validation to be
incomplete where "properties" is not set, but "additionalProperties" is.

This commit fixes both bugs in issue #353.

* Issue-414: Allow The Option of T or space for Date time. (#415)

* Testcase for minProperties with properties defined (#416)

+ Fix Test

* Tweak phpdocumentor dependency to avoid install conflicts (#421)

* [BUGFIX] Cast empty schema arrays to object (#409)

* Cast root to object

* Use function_exists to allow polyfill compatibility

* Move array->object conversion to SchemaConstraint & SchemaStorage

Fixes issue #408

* fix bug when applying defaults for array items when the schema is for (#405)

all items and add support for minItems when applying defaults

* [BUGFIX] Split "uri" format into "uri" & "uri-reference", fix meta-schema bug (#419)

* Split "uri" format into "uri" and "uri-reference"

* Correct format for id & $ref in draft-03/04 meta-schemas

See https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/177#issuecomment-293051367
5.2.1
2017-05-16 16:06:09 -05:00
Erayd
e3c9bccdc3 Backports for 5.2.0 (#368)
* Add URI translation for retrieval & add local copies of spec schema

* Add use line for InvalidArgumentException & adjust scope (#372)

Fixes issue #371

* add quiet option (#382)

* add quiet option

* use verbose instead of quiet

* add quiet option

* always output dump-schema

* always output dump-schema-url

* fix typo and ws

* [BUGFIX] Add provided schema under a dummy / internal URI (fixes #376) (#378)

* Add provided schema under a dummy / internal URI (fixes #376)

In order to resolve internal $ref references within a user-provided
schema, SchemaStorage needs to know about the schema. As user-supplied
schemas do not have an associated URI, use a dummy / internal one instead.

* Remove dangling use

* Change URI to class constant on SchemaStorage

* Add option to disable validation of "format" constraint (#383)

* Add more unit tests (#366)

* Add test coverage for coercion API

* Complete test coverage for SchemaStorage

* Add test coverage for ObjectIterator

* Add exception test for JsonPointer

* MabeEnum\Enum appears to use singletons - add testing const

* Don't check this line for coverage

mbstring is on all test platforms, so this line will never be reached.

* Add test for TypeConstraint::validateTypeNameWording()

* Add test for exception on TypeConstraint::validateType()

* PHPunit doesn't like an explanation with its @codeCoverageIgnore...

* Add various tests for UriRetriever

* Add tests for FileGetContents

* Add tests for JsonSchema\Uri\Retrievers\Curl

* Add missing bad-syntax test file

* Restrict ignore to the exception line only

* Fix exception scope

* Allow the schema to be an associative array (#389)

* Allow the schema to be an associative array

Implements #388.

* Use json_decode(json_encode()) for array -> object cast

* Skip exception check on PHP versions < 5.5.0

* Skip test on HHVM, as it's happy to encode resources

* Enable FILTER_FLAG_EMAIL_UNICODE for email format if present (#398)

* Don't throw exceptions until after checking anyOf / oneOf (#394)

Fixes #393

* Fix infinite recursion on some schemas when setting defaults (#359) (#365)

* Don't try to fetch files that don't exist

Throws an exception when the ref can't be resolved to a useful file URI,
rather than waiting for something further down the line to fail after
the fact.

* Refactor defaults code to use LooseTypeCheck where appropriate

* Test for not treating non-containers like arrays

* Update comments

* Rename variable for clarity

* Add CHECK_MODE_ONLY_REQUIRED_DEFAULTS

If CHECK_MODE_ONLY_REQUIRED_DEFAULTS is set, then only apply defaults
if they are marked as required.

* Workaround for $this scope issue on PHP-5.3

* Fix infinite recursion via $ref when applying defaults

* Add missing second test for array case

* Add test for setting a default value for null

* Also fix infinite recursion via $ref for array defaults

* Move nested closure into separate method

* $parentSchema will always be set when $name is, so don't check it

* Handle nulls properly - fixes issue #377

* Add option to also validate the schema (#357)

* Remove stale files from #357 (obviated by #362) (#400)

* Stop #386 sneaking in alongside another PR backport
5.2.0
2017-03-22 18:43:35 -04:00
Erayd
ef3ee8356a Don't clobber $i (#361) 2017-02-23 17:07:26 -06:00
Erayd
282a63e17b Fix relative-path case where first segment contains a colon (#360) 2017-02-23 17:04:45 -06:00
Erayd
337855de25 Fix non-conforming URL validation (#358)
Json schema spec says URLs are validated as per RFC-3986, but PHP's
FILTER_VALIDATE_URL can't cope with relative path references, which are
explicitly allowed. See https://tools.ietf.org/html/rfc3986#section-4.2
for further information.
2017-02-23 13:00:20 -06:00
Erayd
f6a9111969 Add composer scripts for checking / fixing code style (#356) 2017-02-22 06:07:56 -06:00
Erayd
48817e5f95 Add option to apply default values from the schema (#349)
* Add option to apply default values from the schema

* Clone default objects instead of passing by reference

Objects should always be assigned via clone, to prevent modifications
to the input object from also modifying the underlying schema.

* Run php-cs-fixer

* Remove two duplicate test cases
5.1.0
2017-02-21 21:28:16 -06:00
Rob
42c1043e1c Make code-style more consistent (#355)
* update branch-alias

* add php-cs-fixer configuration

* add php-cs-fixer to travis

* apply code-style rules
2017-02-21 13:11:59 -06:00
Erayd
7eb38e2b20 Option to throw exceptions when an error is encountered (#354)
* Add option to throw an exception on validation errors

* Update README

 * Changes API references to use the new Validator::validate() entry point
 * Adds section describing available config options
2017-02-15 19:56:09 -06:00
Erayd
9b6ebfeece Refactor to simplify the public API and make adding features easier (#351)
This commit makes the following changes:
 * Split the Constraint class to make Validator independent from it
 * Add Validator::validate() as the main entry point
 * Turn Validator::coerce() and Validator::check() into aliases
 * Add Factory::setConfig(), getConfig(), addConfig() & removeConfig()
 * Make type-coercion a checkMode option, don't pass $coerce everywhere
 * Add some extra tests
5.0.0
2017-02-15 10:21:39 -06:00
Francesco Lo Franco
325a0f8c59 Fix regex for Rfc3339 validation (#347) 2017-01-16 09:17:02 -06:00
Max Loeb
d39c56a46b Better coercion (#336)
* Better coercion

* add phpdocs
4.1.0
2016-12-22 10:43:46 -06:00
Remi Collet
1da862247e fix #341 validate-json command (#342) 2016-12-12 14:33:00 -06:00
kynx
3e9f6fb275 Added SchemaStorageInterface (#339) 2016-12-08 12:02:35 -06:00
Iurii Antykhovych
9da41b076f improve validation performance of long string, number and integer arrays (#331)
* improve validation performance of long string and numeric arrays

* update 'Running the thests' section in README.md
2016-12-08 11:29:26 -06:00
jbaron-gingco
24aa1a916a [BUGFIX] Add unicode support in patternProperties and in format constraints (#338) 2016-12-02 11:42:45 -06:00
Rudolf Tucek
a942b987b3 Fix various details in README.md (#335)
Add newline after heading and code block (consistency).

Use triple backticks for bash code examples.

Change how library will be installed via composer.

Remove explicit version constraint in `composer require` example. Recent
versions of composer will default the most recent version and
set a non-major breaking constraint.
Version constraint was still pointing to the most recent version of 2.*
release.

Soft limit text to 80 chars (does node affect code examples).

Remove 'Basic usage' heading.

Fix heading 'Type coercion' (space and typo).

Add missing opening PHP tag (section 'Type coercion'.

Fix indentation in code example (consistent 4 spaces).

Use single backticks for inline code.
Add parenthesis to method in description.
2016-11-25 20:52:44 -06:00
jbaron-gingco
10d1f6977f [BUGFIX] Use unicode matching for patterns, since JSON allows all unicode. (#330) 4.0.1 2016-11-09 10:32:33 -06:00
Max Loeb
52b77d7823 add php lang tag to code block (#328) 2016-10-27 11:34:31 -05:00
Max Loeb
1081a70508 update readme (#326) 2016-10-27 05:52:44 -05:00
Max Loeb
43158d3844 handle negative integers (#325) 2016-10-24 14:51:15 -05:00
Max Loeb
d44cac08da handle coercion of multiple types (#322) 2016-10-24 12:24:56 -04:00
David Porter
4f10e03582 feat(demo): add simple demo script (#319) 2016-10-10 07:42:26 -05:00
bighappyface
828cd2db54 chore(composer): update dev-master 2016-10-10 07:41:21 -05:00
Robert Schönthal
31b29546f4 performance improvements (#310) 4.0.0 2016-10-10 07:37:37 -05:00
David Porter
70a1e2a2e9 chore(phpunit): ignore local phpunit.xml (#318) 2016-10-10 05:28:58 -05:00
David Porter
c3e11beff3 fix(NumberConstraint): force positive value on first arg (#316)
Resolves #315 - `multipleOf` is inconsistent, fails for negative numbers
2016-10-10 05:20:45 -05:00
Max Loeb
d701d8f2ba Add support for $ref on properties (#317)
* add support for  on properties

* use classic array syntax
2016-10-10 04:18:54 +01:00
Kristopher Windsor
0bbaac8cd1 Update README.md to include a second usage example (With inline refs) (#313)
* Update README.md to include a second usage example (With inline references)

* clarity and formatting improvements for recent changes to README.md
2016-10-09 20:38:53 +01:00
Max Loeb
a918d3b5d9 Add support for type coercion (#308)
* add support for type coercion

* add tests

* move coerce tests out of base

* use flags for mode

* update readme

* fix tests

* remove ws

* use binary literals, explicit cast

* back to hex
2016-10-09 20:36:01 +01:00
Michael Calcinai
fa407eb806 Updated to check that is not an object (#314) 2016-10-03 14:46:03 +01:00
Michael Calcinai
26605efbc4 Return points, spelling and dead code (#304)
* Clarity and consistency of return points

* Spelling

* Removed unused declarations and vars

* Updated tests

* Reverted return point change and updated test
2016-10-03 14:32:13 +01:00
Tristan Darricau
2128f9de8b Master is not 2.0.x anymore but 3.0.x (#306) 3.0.1 2016-08-26 07:45:49 -05:00
Dario Nuevo
0f87b314cd add instance cache, remove unnecessary execution paths (#288)
fix wrong merge
2016-08-19 07:57:35 -05:00
Patrick Safarov
1296583112 New way of handling references (#277) 3.0.0 2016-08-15 11:39:11 -05:00
Chris Wilkinson
ef13b9b94c Cache the results of RefResolver::resolve() (#290)
* Cache the results of RefResolver::resolve()

* Add test
2016-08-11 07:35:14 -05:00
David Porter
58b6e07fc0 Merge pull request #276 from steffkes/path-json-pointer
use JsonPointer for path handling
2016-08-11 07:34:30 -05:00
David Porter
38503c48c6 Merge pull request #294 from FlorianSW/issue/293
Change error reporting for invalid types with multiple valid types
2016-08-11 07:32:42 -05:00
steffkes
7851a44591 proper typo - checks format of _an_ element 2016-08-02 22:36:40 +02:00
Florian
53a8486e62 Change error reporting for invalid types with multiple valid types
Currently, if a property has multiple valid types, an error message
when a value doesn't conform to the schema, would mention only the
last valid type, without mentioning the other valid types.

This commit changes, how the TypeConstraint works internally. It
does a little bit of refactoring (removing also the "Refacter this"
ToDo) and now mentions any valid types on a failure.

Fixes #293
2016-08-02 18:19:59 +02:00
steffkes
8c32e3e54d use JsonPointer for path handling 2016-08-02 15:02:29 +02:00
David Porter
ddabcf8025 Merge pull request #286 from boekkooi-fresh/array-as-object
Support json_decode assoc
2016-08-01 19:40:51 -05:00
David Porter
c269bdaa37 Merge pull request #278 from abacaphiliac/exception-interface
Exception interface
2016-07-25 18:45:42 -05:00
David Porter
6b56652c51 Merge pull request #287 from sinbonders/master
Updating to use more correct hostname regex. This fixes #129
2016-07-25 18:44:29 -05:00