Skip to content

Commit

Permalink
Merge pull request #1947 from mab05k/bugfix/subresource-filters
Browse files Browse the repository at this point in the history
Subresource Filter Fix
  • Loading branch information
soyuka committed May 14, 2018
2 parents e91f362 + ec61304 commit 19fc20d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
2 changes: 2 additions & 0 deletions features/main/relation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Feature: Relations support
"@id": "/related_to_dummy_friends/dummyFriend=1;relatedDummy=1",
"@type": "RelatedToDummyFriend",
"name": "Friends relation",
"description": null,
"dummyFriend": {
"@id": "/dummy_friends/1",
"@type": "DummyFriend",
Expand All @@ -117,6 +118,7 @@ Feature: Relations support
"@id": "/related_to_dummy_friends/dummyFriend=1;relatedDummy=1",
"@type": "RelatedToDummyFriend",
"name": "Friends relation",
"description": null,
"dummyFriend": {
"@id": "/dummy_friends/1",
"@type": "DummyFriend",
Expand Down
6 changes: 5 additions & 1 deletion features/swagger/docs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ Feature: Documentation support
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[1].in" should be equal to "query"
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[1].required" should be false
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[1].type" should be equal to "string"
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters" should have 2 element
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[2].name" should be equal to "description"
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[2].in" should be equal to "query"
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[2].required" should be false
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters[2].type" should be equal to "string"
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.parameters" should have 3 element

# Subcollection - check schema
And the JSON node "paths./related_dummies/{id}/related_to_dummy_friends.get.responses.200.schema.items.$ref" should be equal to "#/definitions/RelatedToDummyFriend-fakemanytomany"
Expand Down
2 changes: 1 addition & 1 deletion src/Swagger/Serializer/DocumentationNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function normalize($object, $format = null, array $context = [])
}
}

if ($parameters = $this->getFiltersParameters($resourceClass, $operationName, $subResourceMetadata, $definitions, $serializerContext)) {
if ($parameters = $this->getFiltersParameters($subresourceOperation['resource_class'], $operationName, $subResourceMetadata, $definitions, $serializerContext)) {
foreach ($parameters as $parameter) {
if (!\in_array($parameter['name'], $parametersMemory, true)) {
$pathOperation['parameters'][] = $parameter;
Expand Down
24 changes: 24 additions & 0 deletions tests/Fixtures/TestBundle/Entity/RelatedToDummyFriend.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ class RelatedToDummyFriend
*/
private $name;

/**
* @var string|null The dummy description
*
* @ORM\Column(nullable=true)
* @Groups({"fakemanytomany", "friends"})
*/
private $description;

/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="DummyFriend")
Expand Down Expand Up @@ -64,6 +72,22 @@ public function getName()
return $this->name;
}

/**
* @return null|string
*/
public function getDescription()
{
return $this->description;
}

/**
* @param null|string $description
*/
public function setDescription($description)
{
$this->description = $description;
}

/**
* Gets dummyFriend.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/app/config/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ services:

app.related_dummy_to_friend_resource.search_filter:
parent: 'api_platform.doctrine.orm.search_filter'
arguments: [ { 'name': 'ipartial' } ]
arguments: [ { 'name': 'ipartial', 'description': 'ipartial' } ]
tags: [ { name: 'api_platform.filter', id: 'related_to_dummy_friend.name' } ]

logger:
Expand Down

0 comments on commit 19fc20d

Please sign in to comment.