-
-
Notifications
You must be signed in to change notification settings - Fork 369
feat: Add Draft-2019-09 #885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e5aa59f
Update to json schema test suite main branch (#906)
DannyvdSluijs 5847fcc
Display the additional property on error instead of the value (#904)
nicosp 42ba3cc
feat: Add draft2019 as copy from draft07
DannyvdSluijs 61247d0
fix: Fixes for minContains and maxContains
DannyvdSluijs 04b132a
fix: Skip validation of content due to security concerns
DannyvdSluijs 55f7830
feat: Add dependentSchemas support
DannyvdSluijs 5edc502
feat: Add support for dependentRequired
DannyvdSluijs 9691dca
fix: Add cont and enum support to propertyNames constraint
DannyvdSluijs 16567e4
test: Skip recursiveRef.json test for draft 2019-09
DannyvdSluijs 60fbc73
refactor: Correct return value scope
DannyvdSluijs d99f002
style: Remove unused imports
DannyvdSluijs abd861d
test: Skip more test for draft 2019-09
DannyvdSluijs fbe53a1
test: Skip more test fomr initial implementation
DannyvdSluijs 7268a6b
fix: Correct PHPStan finding
DannyvdSluijs 92a2a81
refactor: Address review comments and fix accross other drafts
DannyvdSluijs ef9b287
refactor: Process feedback
DannyvdSluijs 25c175e
fix: Include json-schema-draft-2019-09.json schema
DannyvdSluijs 75fb83b
docs: Update docs to reflect Draft 2019-09 support
DannyvdSluijs 7a4e9f7
fix: Correct path for constraints that loop over properties
DannyvdSluijs c60cbf4
refactor: Remove redundant check
DannyvdSluijs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2019-09/schema", | ||
| "$id": "https://json-schema.org/draft/2019-09/schema", | ||
| "title": "Core and Validation specifications meta-schema", | ||
| "type": ["object", "boolean"], | ||
| "$defs": { | ||
| "schemaArray": { | ||
| "type": "array", | ||
| "minItems": 1, | ||
| "items": { "$ref": "#" } | ||
| }, | ||
| "nonNegativeInteger": { | ||
| "type": "integer", | ||
| "minimum": 0 | ||
| }, | ||
| "nonNegativeIntegerDefault0": { | ||
| "allOf": [ | ||
| { "$ref": "#/$defs/nonNegativeInteger" }, | ||
| { "default": 0 } | ||
| ] | ||
| }, | ||
| "simpleTypes": { | ||
| "enum": ["array", "boolean", "integer", "null", "number", "object", "string"] | ||
| }, | ||
| "stringArray": { | ||
| "type": "array", | ||
| "items": { "type": "string" }, | ||
| "uniqueItems": true, | ||
| "default": [] | ||
| } | ||
| }, | ||
| "properties": { | ||
| "$id": { "type": "string", "format": "uri-reference" }, | ||
| "$schema": { "type": "string", "format": "uri" }, | ||
| "$anchor": { "type": "string", "pattern": "^[A-Za-z][-A-Za-z0-9.:_]*$" }, | ||
| "$ref": { "type": "string", "format": "uri-reference" }, | ||
| "$recursiveRef": { "type": "string", "format": "uri-reference" }, | ||
| "$recursiveAnchor": { "type": "boolean", "default": false }, | ||
| "$vocabulary": { | ||
| "type": "object", | ||
| "propertyNames": { "type": "string", "format": "uri" }, | ||
| "additionalProperties": { "type": "boolean" } | ||
| }, | ||
| "$comment": { "type": "string" }, | ||
| "$defs": { | ||
| "type": "object", | ||
| "additionalProperties": { "$ref": "#" }, | ||
| "default": {} | ||
| }, | ||
| "definitions": { | ||
| "$comment": "Retained for backwards compatibility, replaced by $defs.", | ||
| "type": "object", | ||
| "additionalProperties": { "$ref": "#" }, | ||
| "default": {} | ||
| }, | ||
| "title": { "type": "string" }, | ||
| "description": { "type": "string" }, | ||
| "default": true, | ||
| "deprecated": { "type": "boolean", "default": false }, | ||
| "readOnly": { "type": "boolean", "default": false }, | ||
| "writeOnly": { "type": "boolean", "default": false }, | ||
| "examples": { "type": "array", "items": true }, | ||
| "multipleOf": { "type": "number", "exclusiveMinimum": 0 }, | ||
| "maximum": { "type": "number" }, | ||
| "exclusiveMaximum": { "type": "number" }, | ||
| "minimum": { "type": "number" }, | ||
| "exclusiveMinimum": { "type": "number" }, | ||
| "maxLength": { "$ref": "#/$defs/nonNegativeInteger" }, | ||
| "minLength": { "$ref": "#/$defs/nonNegativeIntegerDefault0" }, | ||
| "pattern": { "type": "string", "format": "regex" }, | ||
| "additionalItems": { "$ref": "#" }, | ||
| "items": { | ||
| "anyOf": [ | ||
| { "$ref": "#" }, | ||
| { "$ref": "#/$defs/schemaArray" } | ||
| ], | ||
| "default": true | ||
| }, | ||
| "maxItems": { "$ref": "#/$defs/nonNegativeInteger" }, | ||
| "minItems": { "$ref": "#/$defs/nonNegativeIntegerDefault0" }, | ||
| "uniqueItems": { "type": "boolean", "default": false }, | ||
| "contains": { "$ref": "#" }, | ||
| "maxContains": { "$ref": "#/$defs/nonNegativeInteger" }, | ||
| "minContains": { "$ref": "#/$defs/nonNegativeIntegerDefault0" }, | ||
| "unevaluatedItems": { "$ref": "#" }, | ||
| "maxProperties": { "$ref": "#/$defs/nonNegativeInteger" }, | ||
| "minProperties": { "$ref": "#/$defs/nonNegativeIntegerDefault0" }, | ||
| "required": { "$ref": "#/$defs/stringArray" }, | ||
| "additionalProperties": { "$ref": "#" }, | ||
| "unevaluatedProperties": { "$ref": "#" }, | ||
| "properties": { | ||
| "type": "object", | ||
| "additionalProperties": { "$ref": "#" }, | ||
| "default": {} | ||
| }, | ||
| "patternProperties": { | ||
| "type": "object", | ||
| "additionalProperties": { "$ref": "#" }, | ||
| "propertyNames": { "format": "regex" }, | ||
| "default": {} | ||
| }, | ||
| "dependentSchemas": { | ||
| "type": "object", | ||
| "additionalProperties": { "$ref": "#" } | ||
| }, | ||
| "dependentRequired": { | ||
| "type": "object", | ||
| "additionalProperties": { "$ref": "#/$defs/stringArray" } | ||
| }, | ||
| "dependencies": { | ||
| "$comment": "Retained for backwards compatibility, replaced by dependentSchemas/dependentRequired.", | ||
| "type": "object", | ||
| "additionalProperties": { | ||
| "anyOf": [ | ||
| { "$ref": "#" }, | ||
| { "$ref": "#/$defs/stringArray" } | ||
| ] | ||
| } | ||
| }, | ||
| "propertyNames": { "$ref": "#" }, | ||
| "const": true, | ||
| "enum": { | ||
| "type": "array", | ||
| "items": true, | ||
| "minItems": 1, | ||
| "uniqueItems": true | ||
| }, | ||
| "type": { | ||
| "anyOf": [ | ||
| { "$ref": "#/$defs/simpleTypes" }, | ||
| { | ||
| "type": "array", | ||
| "items": { "$ref": "#/$defs/simpleTypes" }, | ||
| "minItems": 1, | ||
| "uniqueItems": true | ||
| } | ||
| ] | ||
| }, | ||
| "format": { "type": "string" }, | ||
| "contentEncoding": { "type": "string" }, | ||
| "contentMediaType": { "type": "string" }, | ||
| "contentSchema": { "$ref": "#" }, | ||
| "if": { "$ref": "#" }, | ||
| "then": { "$ref": "#" }, | ||
| "else": { "$ref": "#" }, | ||
| "allOf": { "$ref": "#/$defs/schemaArray" }, | ||
| "anyOf": { "$ref": "#/$defs/schemaArray" }, | ||
| "oneOf": { "$ref": "#/$defs/schemaArray" }, | ||
| "not": { "$ref": "#" } | ||
| }, | ||
| "default": true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/JsonSchema/Constraints/Drafts/Draft2019/AdditionalItemsConstraint.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace JsonSchema\Constraints\Drafts\Draft2019; | ||
|
|
||
| use JsonSchema\ConstraintError; | ||
| use JsonSchema\Constraints\ConstraintInterface; | ||
| use JsonSchema\Entity\ErrorBagProxy; | ||
| use JsonSchema\Entity\JsonPointer; | ||
|
|
||
| class AdditionalItemsConstraint implements ConstraintInterface | ||
| { | ||
| use ErrorBagProxy; | ||
|
|
||
| /** @var Factory */ | ||
| private $factory; | ||
|
|
||
| public function __construct(?Factory $factory = null) | ||
| { | ||
| $this->factory = $factory ?: new Factory(); | ||
| $this->initialiseErrorBag($this->factory); | ||
| } | ||
|
|
||
| public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null): void | ||
| { | ||
| if (!property_exists($schema, 'additionalItems')) { | ||
| return; | ||
| } | ||
|
|
||
| if ($schema->additionalItems === true) { | ||
| return; | ||
| } | ||
| if ($schema->additionalItems === false && !property_exists($schema, 'items')) { | ||
| return; | ||
| } | ||
|
|
||
| if (!is_array($value)) { | ||
| return; | ||
| } | ||
| if (!property_exists($schema, 'items')) { | ||
| return; | ||
| } | ||
| if (is_object($schema->items)) { | ||
| return; | ||
| } | ||
|
|
||
| $additionalItems = array_diff_key($value, property_exists($schema, 'items') ? $schema->items : []); | ||
| $basePath = $path ?? new JsonPointer(''); | ||
|
|
||
| foreach ($additionalItems as $propertyName => $propertyValue) { | ||
| $incrementedPath = $basePath->withPropertyPaths(array_merge($basePath->getPropertyPaths(), [$propertyName])); | ||
|
|
||
| $schemaConstraint = $this->factory->createInstanceFor('schema'); | ||
| $schemaConstraint->check($propertyValue, $schema->additionalItems, $incrementedPath, $i); | ||
|
|
||
| if ($schemaConstraint->isValid()) { | ||
| continue; | ||
| } | ||
|
|
||
| $this->addError(ConstraintError::ADDITIONAL_ITEMS(), $incrementedPath, ['item' => $i, 'property' => $propertyName, 'additionalItems' => $schema->additionalItems]); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.