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
236 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
return [ | ||
'json-schema-file' => __DIR__ . '/schema.json', | ||
'root-class' => 'Test', | ||
'namespace' => 'Jane\JsonSchema\Tests\Expected', | ||
'directory' => __DIR__ . '/generated', | ||
'use-fixer' => false, | ||
'strict' => true, | ||
]; |
34 changes: 34 additions & 0 deletions
34
src/JsonSchema/Tests/fixtures/array-object-nullable/expected/Model/Attributes.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,34 @@ | ||
<?php | ||
|
||
namespace Jane\JsonSchema\Tests\Expected\Model; | ||
|
||
class Attributes | ||
{ | ||
/** | ||
* | ||
* | ||
* @var string | ||
*/ | ||
protected $foo; | ||
/** | ||
* | ||
* | ||
* @return string | ||
*/ | ||
public function getFoo() : string | ||
{ | ||
return $this->foo; | ||
} | ||
/** | ||
* | ||
* | ||
* @param string $foo | ||
* | ||
* @return self | ||
*/ | ||
public function setFoo(string $foo) : self | ||
{ | ||
$this->foo = $foo; | ||
return $this; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/JsonSchema/Tests/fixtures/array-object-nullable/expected/Model/Document.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,34 @@ | ||
<?php | ||
|
||
namespace Jane\JsonSchema\Tests\Expected\Model; | ||
|
||
class Document | ||
{ | ||
/** | ||
* | ||
* | ||
* @var Attributes[]|null | ||
*/ | ||
protected $attributes; | ||
/** | ||
* | ||
* | ||
* @return Attributes[]|null | ||
*/ | ||
public function getAttributes() : ?array | ||
{ | ||
return $this->attributes; | ||
} | ||
/** | ||
* | ||
* | ||
* @param Attributes[]|null $attributes | ||
* | ||
* @return self | ||
*/ | ||
public function setAttributes(?array $attributes) : self | ||
{ | ||
$this->attributes = $attributes; | ||
return $this; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...nSchema/Tests/fixtures/array-object-nullable/expected/Normalizer/AttributesNormalizer.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,50 @@ | ||
<?php | ||
|
||
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 AttributesNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface | ||
{ | ||
use DenormalizerAwareTrait; | ||
use NormalizerAwareTrait; | ||
public function supportsDenormalization($data, $type, $format = null) | ||
{ | ||
return $type === 'Jane\\JsonSchema\\Tests\\Expected\\Model\\Attributes'; | ||
} | ||
public function supportsNormalization($data, $format = null) | ||
{ | ||
return $data instanceof \Jane\JsonSchema\Tests\Expected\Model\Attributes; | ||
} | ||
public function denormalize($data, $class, $format = null, array $context = array()) | ||
{ | ||
if (!is_object($data)) { | ||
throw new InvalidArgumentException(); | ||
} | ||
if (isset($data->{'$ref'})) { | ||
return new Reference($data->{'$ref'}, $context['document-origin']); | ||
} | ||
if (isset($data->{'$recursiveRef'})) { | ||
return new Reference($data->{'$recursiveRef'}, $context['document-origin']); | ||
} | ||
$object = new \Jane\JsonSchema\Tests\Expected\Model\Attributes(); | ||
if (property_exists($data, 'foo')) { | ||
$object->setFoo($data->{'foo'}); | ||
} | ||
return $object; | ||
} | ||
public function normalize($object, $format = null, array $context = array()) | ||
{ | ||
$data = new \stdClass(); | ||
if (null !== $object->getFoo()) { | ||
$data->{'foo'} = $object->getFoo(); | ||
} | ||
return $data; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...sonSchema/Tests/fixtures/array-object-nullable/expected/Normalizer/DocumentNormalizer.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,68 @@ | ||
<?php | ||
|
||
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 DocumentNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface | ||
{ | ||
use DenormalizerAwareTrait; | ||
use NormalizerAwareTrait; | ||
public function supportsDenormalization($data, $type, $format = null) | ||
{ | ||
return $type === 'Jane\\JsonSchema\\Tests\\Expected\\Model\\Document'; | ||
} | ||
public function supportsNormalization($data, $format = null) | ||
{ | ||
return $data instanceof \Jane\JsonSchema\Tests\Expected\Model\Document; | ||
} | ||
public function denormalize($data, $class, $format = null, array $context = array()) | ||
{ | ||
if (!is_object($data)) { | ||
throw new InvalidArgumentException(); | ||
} | ||
if (isset($data->{'$ref'})) { | ||
return new Reference($data->{'$ref'}, $context['document-origin']); | ||
} | ||
if (isset($data->{'$recursiveRef'})) { | ||
return new Reference($data->{'$recursiveRef'}, $context['document-origin']); | ||
} | ||
$object = new \Jane\JsonSchema\Tests\Expected\Model\Document(); | ||
if (property_exists($data, 'attributes')) { | ||
$value = $data->{'attributes'}; | ||
if (is_array($data->{'attributes'})) { | ||
$values = array(); | ||
foreach ($data->{'attributes'} as $value_1) { | ||
$values[] = $this->denormalizer->denormalize($value_1, 'Jane\\JsonSchema\\Tests\\Expected\\Model\\Attributes', 'json', $context); | ||
} | ||
$value = $values; | ||
} elseif (is_null($data->{'attributes'})) { | ||
$value = $data->{'attributes'}; | ||
} | ||
$object->setAttributes($value); | ||
} | ||
return $object; | ||
} | ||
public function normalize($object, $format = null, array $context = array()) | ||
{ | ||
$data = new \stdClass(); | ||
$value = $object->getAttributes(); | ||
if (is_array($object->getAttributes())) { | ||
$values = array(); | ||
foreach ($object->getAttributes() as $value_1) { | ||
$values[] = $this->normalizer->normalize($value_1, 'json', $context); | ||
} | ||
$value = $values; | ||
} elseif (is_null($object->getAttributes())) { | ||
$value = $object->getAttributes(); | ||
} | ||
$data->{'attributes'} = $value; | ||
return $data; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...JsonSchema/Tests/fixtures/array-object-nullable/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,16 @@ | ||
<?php | ||
|
||
namespace Jane\JsonSchema\Tests\Expected\Normalizer; | ||
|
||
class NormalizerFactory | ||
{ | ||
public static function create() | ||
{ | ||
$normalizers = array(); | ||
$normalizers[] = new \Symfony\Component\Serializer\Normalizer\ArrayDenormalizer(); | ||
$normalizers[] = new \Jane\JsonSchemaRuntime\Normalizer\ReferenceNormalizer(); | ||
$normalizers[] = new DocumentNormalizer(); | ||
$normalizers[] = new AttributesNormalizer(); | ||
return $normalizers; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/JsonSchema/Tests/fixtures/array-object-nullable/schema.json
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 @@ | ||
{ | ||
"$schema": "http://json-schema.org/2019-09/schema#", | ||
"definitions": { | ||
"Document": { | ||
"type": "object", | ||
"properties": { | ||
"attributes": { | ||
"type": ["array", "null"], | ||
"items": { | ||
"$ref": "#/definitions/Attributes" | ||
} | ||
} | ||
} | ||
}, | ||
"Attributes": { | ||
"type": "object", | ||
"properties": { | ||
"foo": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} |