mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-03-12 10:36:09 +03:00
Fix complex groups for jms serializer
This commit is contained in:
parent
01f691c456
commit
d4bf23bcfb
@ -95,8 +95,14 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(empty($model->getGroups()) || !array_key_exists($name, $model->getGroups()) || !is_array($model->getGroups()[$name]))
|
||||||
|
$groups = $model->getGroups();
|
||||||
|
else
|
||||||
|
$groups = $model->getGroups()[$name];
|
||||||
|
|
||||||
|
|
||||||
$property->setRef(
|
$property->setRef(
|
||||||
$this->modelRegistry->register(new Model(new Type(Type::BUILTIN_TYPE_OBJECT, false, $type), $model->getGroups()))
|
$this->modelRegistry->register(new Model(new Type(Type::BUILTIN_TYPE_OBJECT, false, $type), $groups))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ namespace Nelmio\ApiDocBundle\Tests\Functional\Controller;
|
|||||||
|
|
||||||
use Nelmio\ApiDocBundle\Annotation\Model;
|
use Nelmio\ApiDocBundle\Annotation\Model;
|
||||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSUser;
|
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSUser;
|
||||||
|
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSComplex;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||||
use Swagger\Annotations as SWG;
|
use Swagger\Annotations as SWG;
|
||||||
|
|
||||||
@ -29,4 +30,17 @@ class JMSController
|
|||||||
public function userAction()
|
public function userAction()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/api/jms_complex", methods={"GET"})
|
||||||
|
* @SWG\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="Success",
|
||||||
|
* @Model(type=JMSComplex::class, groups={"list", "details", "user" : {"list"}})
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function complexAction()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
43
Tests/Functional/Entity/JMSComplex.php
Normal file
43
Tests/Functional/Entity/JMSComplex.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: Frisks
|
||||||
|
* Date: 2/12/2017
|
||||||
|
* Time: 1:18 PM
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity;
|
||||||
|
|
||||||
|
use JMS\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class JMSComplex
|
||||||
|
* @package Nelmio\ApiDocBundle\Tests\Functional\Entity
|
||||||
|
* @Serializer\ExclusionPolicy("all")
|
||||||
|
*/
|
||||||
|
class JMSComplex
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Serializer\Type("integer")
|
||||||
|
* @Serializer\Expose
|
||||||
|
* @Serializer\Groups({"list"})
|
||||||
|
*/
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Serializer\Type("Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSUser")
|
||||||
|
* @Serializer\Expose
|
||||||
|
* @Serializer\Groups({"details"})
|
||||||
|
*/
|
||||||
|
private $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Serializer\Type("string")
|
||||||
|
* @Serializer\Expose
|
||||||
|
* @Serializer\Groups({"list"})
|
||||||
|
*/
|
||||||
|
private $name;
|
||||||
|
|
||||||
|
}
|
@ -24,7 +24,7 @@ class JMSUser
|
|||||||
/**
|
/**
|
||||||
* @Serializer\Type("integer")
|
* @Serializer\Type("integer")
|
||||||
* @Serializer\Expose
|
* @Serializer\Expose
|
||||||
*
|
* @Serializer\Groups({"list"})
|
||||||
* @SWG\Property(description = "User id", required = true, readOnly = true, title = "userid", example=1)
|
* @SWG\Property(description = "User id", required = true, readOnly = true, title = "userid", example=1)
|
||||||
*/
|
*/
|
||||||
private $id;
|
private $id;
|
||||||
@ -32,8 +32,8 @@ class JMSUser
|
|||||||
/**
|
/**
|
||||||
* @Serializer\Type("string")
|
* @Serializer\Type("string")
|
||||||
* @Serializer\Expose
|
* @Serializer\Expose
|
||||||
*
|
|
||||||
* @SWG\Property(readOnly = false)
|
* @SWG\Property(readOnly = false)
|
||||||
|
* @Serializer\Groups({"details"})
|
||||||
*/
|
*/
|
||||||
private $email;
|
private $email;
|
||||||
|
|
||||||
|
@ -49,6 +49,32 @@ class JMSFunctionalTest extends WebTestCase
|
|||||||
], $this->getModel('JMSUser')->toArray());
|
], $this->getModel('JMSUser')->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testModelComplexDocumentation()
|
||||||
|
{
|
||||||
|
$this->assertEquals([
|
||||||
|
'type' => 'object',
|
||||||
|
'properties' => [
|
||||||
|
'id' => ['type' => 'integer'],
|
||||||
|
'user' => ['$ref' => '#/definitions/JMSUser2'],
|
||||||
|
'name' => ['type' => 'string']
|
||||||
|
],
|
||||||
|
], $this->getModel('JMSComplex')->toArray());
|
||||||
|
|
||||||
|
$this->assertEquals([
|
||||||
|
'type' => 'object',
|
||||||
|
'properties' => [
|
||||||
|
'id' => [
|
||||||
|
'type' => 'integer',
|
||||||
|
'title' => 'userid',
|
||||||
|
'description' => 'User id',
|
||||||
|
'readOnly' => true,
|
||||||
|
'example' => '1',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
], $this->getModel('JMSUser2')->toArray());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected static function createKernel(array $options = array())
|
protected static function createKernel(array $options = array())
|
||||||
{
|
{
|
||||||
return new TestKernel(true);
|
return new TestKernel(true);
|
||||||
|
@ -37,13 +37,14 @@
|
|||||||
"symfony/browser-kit": "^2.8|^3.0|^4.0",
|
"symfony/browser-kit": "^2.8|^3.0|^4.0",
|
||||||
"symfony/cache": "^3.1|^4.0",
|
"symfony/cache": "^3.1|^4.0",
|
||||||
"symfony/phpunit-bridge": "^3.3",
|
"symfony/phpunit-bridge": "^3.3",
|
||||||
|
"symfony/stopwatch": "^2.8|^3.0|^4.0",
|
||||||
"sensio/framework-extra-bundle": "^3.0",
|
"sensio/framework-extra-bundle": "^3.0",
|
||||||
"doctrine/annotations": "^1.2",
|
"doctrine/annotations": "^1.2",
|
||||||
|
|
||||||
"phpdocumentor/reflection-docblock": "^3.1",
|
"phpdocumentor/reflection-docblock": "^3.1",
|
||||||
"api-platform/core": "^2.0.3",
|
"api-platform/core": "^2.0.3",
|
||||||
"friendsofsymfony/rest-bundle": "^2.0",
|
"friendsofsymfony/rest-bundle": "^2.0",
|
||||||
"jms/serializer-bundle": "^1.0|^2.0"
|
"jms/serializer-bundle": "^2.0"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"phpdocumentor/reflection-docblock": "For parsing php docs.",
|
"phpdocumentor/reflection-docblock": "For parsing php docs.",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user