This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from sagikazarmark/multiple_typehint
Prevent the same typehint to appear multiple times in the return docblock
- Loading branch information
Showing
6 changed files
with
121 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Joli\Jane\OpenApi\Tests\Expected\Model; | ||
|
||
class Error | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $message; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getMessage() | ||
{ | ||
return $this->message; | ||
} | ||
|
||
/** | ||
* @param string $message | ||
* | ||
* @return self | ||
*/ | ||
public function setMessage($message = null) | ||
{ | ||
$this->message = $message; | ||
|
||
return $this; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
tests/fixtures/model-in-response/expected/Normalizer/ErrorNormalizer.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,58 @@ | ||
<?php | ||
|
||
namespace Joli\Jane\OpenApi\Tests\Expected\Normalizer; | ||
|
||
use Joli\Jane\Reference\Reference; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
use Symfony\Component\Serializer\Normalizer\SerializerAwareNormalizer; | ||
|
||
class ErrorNormalizer extends SerializerAwareNormalizer implements DenormalizerInterface, NormalizerInterface | ||
{ | ||
public function supportsDenormalization($data, $type, $format = null) | ||
{ | ||
if ($type !== 'Joli\\Jane\\OpenApi\\Tests\\Expected\\Model\\Error') { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function supportsNormalization($data, $format = null) | ||
{ | ||
if ($data instanceof \Joli\Jane\OpenApi\Tests\Expected\Model\Error) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function denormalize($data, $class, $format = null, array $context = []) | ||
{ | ||
if (empty($data)) { | ||
return null; | ||
} | ||
if (isset($data->{'$ref'})) { | ||
return new Reference($data->{'$ref'}, $context['rootSchema'] ?: null); | ||
} | ||
$object = new \Joli\Jane\OpenApi\Tests\Expected\Model\Error(); | ||
if (!isset($context['rootSchema'])) { | ||
$context['rootSchema'] = $object; | ||
} | ||
if (isset($data->{'message'})) { | ||
$object->setMessage($data->{'message'}); | ||
} | ||
|
||
return $object; | ||
} | ||
|
||
public function normalize($object, $format = null, array $context = []) | ||
{ | ||
$data = new \stdClass(); | ||
if (null !== $object->getMessage()) { | ||
$data->{'message'} = $object->getMessage(); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
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