-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
7 changed files
with
235 additions
and
11 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
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
return [ | ||
'json-schema-file' => __DIR__ . '/schema.json', | ||
'root-class' => 'Test', | ||
'namespace' => 'Jane\JsonSchema\Tests\Expected', | ||
'directory' => __DIR__ . '/generated', | ||
]; |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file has been auto generated by Jane, | ||
* | ||
* Do no edit it directly. | ||
*/ | ||
|
||
namespace Jane\JsonSchema\Tests\Expected\Model; | ||
|
||
class Foo | ||
{ | ||
/** | ||
* @var string|object|null[] | ||
*/ | ||
protected $foo; | ||
|
||
/** | ||
* @return string|object|null[] | ||
*/ | ||
public function getFoo() | ||
{ | ||
return $this->foo; | ||
} | ||
|
||
/** | ||
* @param string|object|null[] $foo | ||
* | ||
* @return self | ||
*/ | ||
public function setFoo($foo): self | ||
{ | ||
$this->foo = $foo; | ||
|
||
return $this; | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
Tests/fixtures/one-of/expected/Normalizer/FooNormalizer.php
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file has been auto generated by Jane, | ||
* | ||
* Do no edit it directly. | ||
*/ | ||
|
||
namespace Jane\JsonSchema\Tests\Expected\Normalizer; | ||
|
||
use Jane\JsonSchemaRuntime\Reference; | ||
use Symfony\Component\Serializer\Exception\InvalidArgumentException; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
class FooNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface | ||
{ | ||
use DenormalizerAwareTrait; | ||
use NormalizerAwareTrait; | ||
|
||
public function supportsDenormalization($data, $type, $format = null) | ||
{ | ||
return $type === 'Jane\\JsonSchema\\Tests\\Expected\\Model\\Foo'; | ||
} | ||
|
||
public function supportsNormalization($data, $format = null) | ||
{ | ||
return $data instanceof \Jane\JsonSchema\Tests\Expected\Model\Foo; | ||
} | ||
|
||
public function denormalize($data, $class, $format = null, array $context = []) | ||
{ | ||
if (!is_object($data)) { | ||
throw new InvalidArgumentException(); | ||
} | ||
if (isset($data->{'$ref'})) { | ||
return new Reference($data->{'$ref'}, $context['document-origin']); | ||
} | ||
$object = new \Jane\JsonSchema\Tests\Expected\Model\Foo(); | ||
if (property_exists($data, 'foo')) { | ||
$value = $data->{'foo'}; | ||
if (is_string($data->{'foo'})) { | ||
$value = $data->{'foo'}; | ||
} elseif (isset($data->{'foo'})) { | ||
$values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS); | ||
foreach ($data->{'foo'} as $key => $value_1) { | ||
if (preg_match('/^[a-zA-Z0-9._-]+$/', $key) && isset($value_1)) { | ||
$value_2 = $value_1; | ||
if (is_object($value_1)) { | ||
$value_2 = $value_1; | ||
} elseif (is_null($value_1)) { | ||
$value_2 = $value_1; | ||
} | ||
$values[$key] = $value_2; | ||
continue; | ||
} | ||
} | ||
$value = $values; | ||
} | ||
$object->setFoo($value); | ||
} | ||
|
||
return $object; | ||
} | ||
|
||
public function normalize($object, $format = null, array $context = []) | ||
{ | ||
$data = new \stdClass(); | ||
if (null !== $object->getFoo()) { | ||
$value = $object->getFoo(); | ||
if (is_string($object->getFoo())) { | ||
$value = $object->getFoo(); | ||
} elseif (!is_null($object->getFoo())) { | ||
$values = new \stdClass(); | ||
foreach ($object->getFoo() as $key => $value_1) { | ||
if (preg_match('/^[a-zA-Z0-9._-]+$/', $key) && !is_null($value_1)) { | ||
$value_2 = $value_1; | ||
if (is_object($value_1)) { | ||
$value_2 = $value_1; | ||
} elseif (is_null($value_1)) { | ||
$value_2 = $value_1; | ||
} | ||
$values->{$key} = $value_2; | ||
continue; | ||
} | ||
} | ||
$value = $values; | ||
} | ||
$data->{'foo'} = $value; | ||
} | ||
|
||
return $data; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Tests/fixtures/one-of/expected/Normalizer/NormalizerFactory.php
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file has been auto generated by Jane, | ||
* | ||
* Do no edit it directly. | ||
*/ | ||
|
||
namespace Jane\JsonSchema\Tests\Expected\Normalizer; | ||
|
||
class NormalizerFactory | ||
{ | ||
public static function create() | ||
{ | ||
$normalizers = []; | ||
$normalizers[] = new \Symfony\Component\Serializer\Normalizer\ArrayDenormalizer(); | ||
$normalizers[] = new \Jane\JsonSchemaRuntime\Normalizer\ReferenceNormalizer(); | ||
$normalizers[] = new FooNormalizer(); | ||
|
||
return $normalizers; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"id": "http://json-schema.org/draft-04/schema#", | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"description": "Schema with definitions", | ||
"definitions": { | ||
"Foo": { | ||
"type": "object", | ||
"properties": { | ||
"foo": { | ||
"oneOf": [ | ||
{ | ||
"$ref":"#/definitions/list_of_strings" | ||
}, | ||
{ | ||
"type":"object", | ||
"patternProperties":{ | ||
"^[a-zA-Z0-9._-]+$":{ | ||
"oneOf":[ | ||
{ | ||
"type":"object", | ||
"properties":{ | ||
"aliases":{ | ||
"$ref":"#/definitions/list_of_strings" | ||
}, | ||
"ipv4_address":{ | ||
"type":"string" | ||
}, | ||
"ipv6_address":{ | ||
"type":"string" | ||
} | ||
}, | ||
"additionalProperties":false | ||
}, | ||
{ | ||
"type":"null" | ||
} | ||
] | ||
} | ||
}, | ||
"additionalProperties":false | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"list_of_strings": { | ||
"type": "string", | ||
"enum": [ | ||
"a", "b", "c" | ||
] | ||
} | ||
} | ||
} |