-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1707a9a
commit f20a682
Showing
1 changed file
with
4 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -78,10 +78,11 @@ $schema->toArray(); | |
|
||
// Convert to JSON string | ||
$schema->toJson(); | ||
$schema->toJson(JSON_PRETTY_PRINT); | ||
|
||
$data = [ | ||
'name' => 'John Doe', | ||
'email' => '[email protected]', | ||
'email' => 'foo', // invalid email | ||
'age' => 16, | ||
'active' => true, | ||
'settings' => [ | ||
|
@@ -97,7 +98,7 @@ try { | |
} | ||
|
||
// Or just get a boolean | ||
$schema->isValid($data); | ||
$schema->isValid($data); // false | ||
``` | ||
|
||
## Available Schema Types | ||
|
@@ -453,40 +454,8 @@ $schema | |
|
||
## Converting to JSON Schema | ||
|
||
You can convert any schema to a JSON Schema array or JSON string: | ||
|
||
```php | ||
// Convert to array | ||
$jsonSchemaArray = $schema->toArray(); | ||
|
||
// Convert to JSON string | ||
$jsonSchemaString = $schema->toJson(); | ||
$jsonSchemaString = $schema->toJson(JSON_PRETTY_PRINT); | ||
``` | ||
|
||
This will output a valid JSON Schema that can be used with any JSON Schema validator. | ||
TODO | ||
|
||
Example JSON output: | ||
```json | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"title": "user", | ||
"description": "User schema", | ||
"required": ["name", "email"], | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"minLength": 2, | ||
"maxLength": 100 | ||
}, | ||
"email": { | ||
"type": "string", | ||
"format": "email" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Credits | ||
|
||
|