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 #170 from Korbeil/fix/deprecated-behavior
Fix deprecated behavior in OpenAPI
- Loading branch information
Showing
9 changed files
with
188 additions
and
3 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
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 [ | ||
'openapi-file' => __DIR__ . '/swagger.yaml', | ||
'namespace' => 'Jane\OpenApi\Tests\Expected', | ||
'directory' => __DIR__ . '/generated', | ||
'use-fixer' => false, | ||
]; |
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,17 @@ | ||
<?php | ||
|
||
namespace Jane\OpenApi\Tests\Expected; | ||
|
||
class Client extends \Jane\OpenApiRuntime\Client\Psr7HttplugClient | ||
{ | ||
public static function create($httpClient = null) | ||
{ | ||
if (null === $httpClient) { | ||
$httpClient = \Http\Discovery\HttpClientDiscovery::find(); | ||
} | ||
$messageFactory = \Http\Discovery\MessageFactoryDiscovery::find(); | ||
$streamFactory = \Http\Discovery\StreamFactoryDiscovery::find(); | ||
$serializer = new \Symfony\Component\Serializer\Serializer(\Jane\OpenApi\Tests\Expected\Normalizer\NormalizerFactory::create(), array(new \Symfony\Component\Serializer\Encoder\JsonEncoder(new \Symfony\Component\Serializer\Encoder\JsonEncode(), new \Symfony\Component\Serializer\Encoder\JsonDecode()))); | ||
return new static($httpClient, $messageFactory, $serializer, $streamFactory); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/OpenApi/Tests/fixtures/deprecated/expected/Model/Foo.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,71 @@ | ||
<?php | ||
|
||
namespace Jane\OpenApi\Tests\Expected\Model; | ||
|
||
/** | ||
* | ||
* @deprecated | ||
*/ | ||
class Foo | ||
{ | ||
/** | ||
* | ||
* | ||
* @var string | ||
*/ | ||
protected $email; | ||
/** | ||
* | ||
* | ||
* @deprecated | ||
* | ||
* @var string | ||
*/ | ||
protected $bar; | ||
/** | ||
* | ||
* | ||
* @return string | ||
*/ | ||
public function getEmail() : string | ||
{ | ||
return $this->email; | ||
} | ||
/** | ||
* | ||
* | ||
* @param string $email | ||
* | ||
* @return self | ||
*/ | ||
public function setEmail(string $email) : self | ||
{ | ||
$this->email = $email; | ||
return $this; | ||
} | ||
/** | ||
* | ||
* | ||
* @deprecated | ||
* | ||
* @return string | ||
*/ | ||
public function getBar() : string | ||
{ | ||
return $this->bar; | ||
} | ||
/** | ||
* | ||
* | ||
* @param string $bar | ||
* | ||
* @deprecated | ||
* | ||
* @return self | ||
*/ | ||
public function setBar(string $bar) : self | ||
{ | ||
$this->bar = $bar; | ||
return $this; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/OpenApi/Tests/fixtures/deprecated/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,46 @@ | ||
<?php | ||
|
||
namespace Jane\OpenApi\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\\OpenApi\\Tests\\Expected\\Model\\Foo'; | ||
} | ||
public function supportsNormalization($data, $format = null) | ||
{ | ||
return is_object($data) && get_class($data) === 'Jane\\OpenApi\\Tests\\Expected\\Model\\Foo'; | ||
} | ||
public function denormalize($data, $class, $format = null, array $context = array()) | ||
{ | ||
if (!is_object($data)) { | ||
throw new InvalidArgumentException(); | ||
} | ||
$object = new \Jane\OpenApi\Tests\Expected\Model\Foo(); | ||
if (property_exists($data, 'email')) { | ||
$object->setEmail($data->{'email'}); | ||
} | ||
if (property_exists($data, 'bar')) { | ||
$object->setBar($data->{'bar'}); | ||
} | ||
return $object; | ||
} | ||
public function normalize($object, $format = null, array $context = array()) | ||
{ | ||
$data = new \stdClass(); | ||
$data->{'email'} = $object->getEmail(); | ||
$data->{'bar'} = $object->getBar(); | ||
return $data; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/OpenApi/Tests/fixtures/deprecated/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,14 @@ | ||
<?php | ||
|
||
namespace Jane\OpenApi\Tests\Expected\Normalizer; | ||
|
||
class NormalizerFactory | ||
{ | ||
public static function create() | ||
{ | ||
$normalizers = array(); | ||
$normalizers[] = new \Symfony\Component\Serializer\Normalizer\ArrayDenormalizer(); | ||
$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,15 @@ | ||
openapi: 3.0.0 | ||
info: | ||
version: '' | ||
title: '' | ||
components: | ||
schemas: | ||
Foo: | ||
type: object | ||
deprecated: true | ||
properties: | ||
email: | ||
type: string | ||
bar: | ||
type: string | ||
deprecated: true |