-
-
Notifications
You must be signed in to change notification settings - Fork 844
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improves iri_only implementation (#3454)
* Issue-#3275 - feat: Improves iri_only implementation (#3454) * Add back default context * fix: minor fixes Co-authored-by: soyuka <soyuka@users.noreply.github.com> Co-authored-by: Alan Poulain <contact@alanpoulain.eu>
- Loading branch information
1 parent
b322aff
commit 1c7c26d
Showing
10 changed files
with
298 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
Feature: JSON-LD using iri_only parameter | ||
In order to improve Vulcain support | ||
As a Vulcain user and as a developer | ||
I should be able to only get an IRI list when I ask a resource. | ||
|
||
Scenario: Retrieve Dummy's resource context with iri_only | ||
When I send a "GET" request to "/contexts/IriOnlyDummy" | ||
Then the response status code should be 200 | ||
And the response should be in JSON | ||
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" | ||
And the JSON should be equal to: | ||
""" | ||
{ | ||
"@context": { | ||
"@vocab": "http://example.com/docs.jsonld#", | ||
"hydra": "http://www.w3.org/ns/hydra/core#", | ||
"hydra:member": { | ||
"@type": "@id" | ||
} | ||
} | ||
} | ||
""" | ||
|
||
@createSchema | ||
Scenario: Retrieve Dummies with iri_only and jsonld_embed_context | ||
Given there are 3 iriOnlyDummies | ||
When I send a "GET" request to "/iri_only_dummies" | ||
Then the response status code should be 200 | ||
And the response should be in JSON | ||
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" | ||
And the JSON should be equal to: | ||
""" | ||
{ | ||
"@context": { | ||
"@vocab": "http://example.com/docs.jsonld#", | ||
"hydra": "http://www.w3.org/ns/hydra/core#", | ||
"hydra:member": { | ||
"@type": "@id" | ||
} | ||
}, | ||
"@id": "/iri_only_dummies", | ||
"@type": "hydra:Collection", | ||
"hydra:member": [ | ||
"/iri_only_dummies/1", | ||
"/iri_only_dummies/2", | ||
"/iri_only_dummies/3" | ||
], | ||
"hydra:totalItems": 3 | ||
} | ||
""" |
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,62 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Document; | ||
|
||
use ApiPlatform\Core\Annotation\ApiResource; | ||
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; | ||
|
||
/** | ||
* Dummy with iri_only. | ||
* | ||
* @author Pierre Thibaudeau <pierre.thibaudeau@les-tilleuls.coop> | ||
* | ||
* @ApiResource( | ||
* normalizationContext={ | ||
* "iri_only"=true, | ||
* "jsonld_embed_context"=true | ||
* } | ||
* ) | ||
* @ODM\Document | ||
*/ | ||
class IriOnlyDummy | ||
{ | ||
/** | ||
* @var int The id | ||
* | ||
* @ODM\Id(strategy="INCREMENT", type="integer") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string | ||
* | ||
* @ODM\Field(type="string") | ||
*/ | ||
private $foo; | ||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getFoo(): string | ||
{ | ||
return $this->foo; | ||
} | ||
|
||
public function setFoo(string $foo): void | ||
{ | ||
$this->foo = $foo; | ||
} | ||
} |
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,64 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity; | ||
|
||
use ApiPlatform\Core\Annotation\ApiResource; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* Dummy with iri_only. | ||
* | ||
* @author Pierre Thibaudeau <pierre.thibaudeau@les-tilleuls.coop> | ||
* | ||
* @ApiResource( | ||
* normalizationContext={ | ||
* "iri_only"=true, | ||
* "jsonld_embed_context"=true | ||
* } | ||
* ) | ||
* @ORM\Entity | ||
*/ | ||
class IriOnlyDummy | ||
{ | ||
/** | ||
* @var int The id | ||
* | ||
* @ORM\Column(type="integer") | ||
* @ORM\Id | ||
* @ORM\GeneratedValue(strategy="AUTO") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string | ||
* | ||
* @ORM\Column(type="string") | ||
*/ | ||
private $foo; | ||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getFoo(): string | ||
{ | ||
return $this->foo; | ||
} | ||
|
||
public function setFoo(string $foo): void | ||
{ | ||
$this->foo = $foo; | ||
} | ||
} |
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
Oops, something went wrong.