mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Merge pull request #1132 from 7thcubic/complex_groups
Fix complex groups context for jms models
This commit is contained in:
commit
8a53891ee9
@ -100,8 +100,15 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!array_key_exists($name, $model->getGroups()) || !is_array($model->getGroups()[$name])) {
|
||||
$groups = $model->getGroups();
|
||||
} else {
|
||||
$groups = $model->getGroups()[$name];
|
||||
}
|
||||
|
||||
|
||||
$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\Tests\Functional\Entity\JMSUser;
|
||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\JMSComplex;
|
||||
use Nelmio\ApiDocBundle\Tests\Functional\Entity\VirtualProperty;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Swagger\Annotations as SWG;
|
||||
@ -42,4 +43,16 @@ class JMSController
|
||||
public function yamlAction()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @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,6 +24,7 @@ class JMSUser
|
||||
/**
|
||||
* @Serializer\Type("integer")
|
||||
* @Serializer\Expose
|
||||
* @Serializer\Groups({"list"})
|
||||
*
|
||||
* @SWG\Property(description = "User id", required = true, readOnly = true, title = "userid", example=1, default = null)
|
||||
*/
|
||||
@ -41,8 +42,8 @@ class JMSUser
|
||||
/**
|
||||
* @Serializer\Type("string")
|
||||
* @Serializer\Expose
|
||||
*
|
||||
* @SWG\Property(readOnly = false)
|
||||
* @Serializer\Groups({"details"})
|
||||
*/
|
||||
private $email;
|
||||
|
||||
|
@ -63,6 +63,31 @@ class JMSFunctionalTest extends WebTestCase
|
||||
], $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());
|
||||
}
|
||||
|
||||
public function testYamlConfig()
|
||||
{
|
||||
$this->assertEquals([
|
||||
|
@ -34,6 +34,7 @@
|
||||
"symfony/browser-kit": "^2.8|^3.0|^4.0",
|
||||
"symfony/cache": "^3.1|^4.0",
|
||||
"symfony/phpunit-bridge": "^3.3",
|
||||
"symfony/stopwatch": "^2.8|^3.0|^4.0",
|
||||
"sensio/framework-extra-bundle": "^3.0",
|
||||
"symfony/stopwatch": "^2.8|^3.0|^4.0",
|
||||
"doctrine/annotations": "^1.2",
|
||||
|
Loading…
x
Reference in New Issue
Block a user