Created
March 11, 2016 16:06
-
-
Save fezfez/607284fccee9675162d7 to your computer and use it in GitHub Desktop.
Conflict with swagger Annotation and Doctrine2 Annotation
This file contains hidden or 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
| { | |
| "name": "prove/bug", | |
| "description": "", | |
| "type": "application", | |
| "prefer-stable" : true, | |
| "require": { | |
| "zircote/swagger-php": "^2.0", | |
| "willdurand/hateoas": "^2.9" | |
| } | |
| } |
This file contains hidden or 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
| <?php | |
| use Hateoas\HateoasBuilder; | |
| use Doctrine\Common\Annotations\AnnotationRegistry; | |
| use Doctrine\Common\Annotations\AnnotationReader; | |
| use Swagger\Annotations as SWG; | |
| use JMS\Serializer\Annotation as JMS; | |
| use Hateoas\Configuration\Annotation as Hateoas; | |
| require("../vendor/autoload.php"); | |
| AnnotationReader::addGlobalIgnoredName('Swagger\Annotations\Definition'); | |
| AnnotationRegistry::registerAutoloadNamespace('JMS\Serializer\Annotation', __DIR__. "/../vendor/jms/serializer/src"); | |
| AnnotationRegistry::registerAutoloadNamespace('Hateoas\Configuration\Annotation', __DIR__. "/../vendor/willdurand/hateoas/src"); | |
| /** | |
| * @SWG\Swagger( | |
| * @SWG\Info( | |
| * title="My first swagger documented API", | |
| * version="1.0.0" | |
| * ) | |
| * ) | |
| */ | |
| /** | |
| * @SWG\Definition(definition="Test") | |
| * @JMS\XmlRoot("Test") | |
| * @Hateoas\Relation("self", href = "expr('/api/test/' ~ object.getReference())") | |
| */ | |
| class Test | |
| { | |
| /** | |
| * @var int | |
| * | |
| * @JMS\XmlAttribute | |
| */ | |
| private $id; | |
| /** | |
| * @var string | |
| * | |
| * @JMS\XmlAttribute | |
| * @SWG\Property(type="string") | |
| */ | |
| private $reference; | |
| public function setReference($value) | |
| { | |
| $this->reference = $value; | |
| } | |
| } | |
| if (isset($_GET['get'])) { | |
| $hateoas = HateoasBuilder::create()->build(); | |
| $user = new Test(); | |
| $user->setReference('fezfe'); | |
| $json = $hateoas->serialize($user, 'json'); | |
| $xml = $hateoas->serialize($user, 'xml'); | |
| header('Content-Type: application/json'); | |
| echo($json); | |
| } else { | |
| $swagger = \Swagger\scan(__FILE__); | |
| header('Content-Type: application/json'); | |
| echo $swagger; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment