PHP code example of openregion / php-json-schema-generator
1. Go to this page and download the library: Download openregion/php-json-schema-generator library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
openregion / php-json-schema-generator example snippets
$output = JSONSchemaGenerator\Generator::fromJson('{"a":{"b":2}');
// $output ==> json string
// {
// "$schema": "http://json-schema.org/draft-04/schema#",
// "type": "object",
// "properties": {
// "a": {
// "type": "object",
// "properties": {
// "b": {
// "type": "integer"
// }
// },
// "
[
'schema_id' => null,
'properties_4/schema#',
'schema_title' => null,
'schema_description' => null,
'schema_type' => null,
"items_schema_collect_mode" => 0,
'schema_
$result = Generator::fromJson($this->addressJson1, [
'schema_id' => 'http://foo.bar/schema'
]);
/*
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://foo.bar/schema",
"type": "object",
"properties": {
"a": {
"type": "object",
"id": "http://foo.bar/schema/a",
"properties": {
"b": {
"id": "http://foo.bar/schema/a/b",
"type": "integer"
}
}
}
}
*/
// if you want items as strict lists instead of "anyOf" type
$result = Generator::fromJson($this->addressJson1, [
'schema_id' => 'http://bar.foo/schema2',
'schema_title' => 'coucouc',
'schema_description' => 'desc',
"items_schema_collect_mode" => Definition::ITEMS_AS_LIST,
]);
/*
{
"$schema":"http:\/\/json-schema.org\/draft-04\/schema#",
...
"properties": {
"phoneNumber":{
"id":"http:\/\/bar.foo\/schema2\/phoneNumber",
"type":"array",
"items": [
{"id":"http:\/\/bar.foo\/schema2\/0",...},
{"id":"http:\/\/bar.foo\/schema2\/1",...}}
*/