Skip to content

Commit 3b6c5e5

Browse files
mab05kantograssiot
authored andcommitted
apply absolute url to all generated URLs/IRIs
1 parent 9b1e202 commit 3b6c5e5

File tree

15 files changed

+341
-36
lines changed

15 files changed

+341
-36
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
@absoluteUrl
2+
Feature: IRI should contain Absolute URL
3+
In order to add detail to IRIs
4+
Include the absolute url
5+
6+
@createSchema
7+
Scenario: I should be able to GET a collection of Objects with Absolute Urls
8+
Given there are 1 absoluteUrlDummy objects with a related absoluteUrlRelationDummy
9+
And I add "Accept" header equal to "application/hal+json"
10+
And I add "Content-Type" header equal to "application/json"
11+
And I send a "GET" request to "/absolute_url_dummies"
12+
And the JSON should be equal to:
13+
"""
14+
{
15+
"_links": {
16+
"self": {
17+
"href": "http:\/\/example.com\/absolute_url_dummies"
18+
},
19+
"item": [
20+
{
21+
"href": "http:\/\/example.com\/absolute_url_dummies\/1"
22+
}
23+
]
24+
},
25+
"totalItems": 1,
26+
"itemsPerPage": 3,
27+
"_embedded": {
28+
"item": [
29+
{
30+
"_links": {
31+
"self": {
32+
"href": "http:\/\/example.com\/absolute_url_dummies\/1"
33+
},
34+
"absoluteUrlRelationDummy": {
35+
"href": "http:\/\/example.com\/absolute_url_relation_dummies\/1"
36+
}
37+
},
38+
"id": 1
39+
}
40+
]
41+
}
42+
}
43+
"""
44+
45+
Scenario: I should be able to POST an object using an Absolute Url
46+
Given I add "Accept" header equal to "application/hal+json"
47+
And I add "Content-Type" header equal to "application/json"
48+
And I send a "POST" request to "/absolute_url_relation_dummies" with body:
49+
"""
50+
{
51+
"absolute_url_dummies": "http://example.com/absolute_url_dummies/1"
52+
}
53+
"""
54+
Then the response status code should be 201
55+
And the JSON should be equal to:
56+
"""
57+
{
58+
"_links": {
59+
"self": {
60+
"href": "http:\/\/example.com\/absolute_url_relation_dummies\/2"
61+
}
62+
},
63+
"id": 2
64+
}
65+
"""
66+
67+
Scenario: I should be able to GET an Item with Absolute Urls
68+
Given I add "Accept" header equal to "application/hal+json"
69+
And I add "Content-Type" header equal to "application/json"
70+
And I send a "GET" request to "/absolute_url_dummies/1"
71+
And the JSON should be equal to:
72+
"""
73+
{
74+
"_links": {
75+
"self": {
76+
"href": "http:\/\/example.com\/absolute_url_dummies\/1"
77+
},
78+
"absoluteUrlRelationDummy": {
79+
"href": "http:\/\/example.com\/absolute_url_relation_dummies\/1"
80+
}
81+
},
82+
"id": 1
83+
}
84+
"""
85+
86+
Scenario: I should be able to GET subresources with Absolute Urls
87+
Given I add "Accept" header equal to "application/hal+json"
88+
And I add "Content-Type" header equal to "application/json"
89+
And I send a "GET" request to "/absolute_url_relation_dummies/1/absolute_url_dummies"
90+
And the JSON should be equal to:
91+
"""
92+
{
93+
"_links": {
94+
"self": {
95+
"href": "http:\/\/example.com\/absolute_url_relation_dummies\/1\/absolute_url_dummies"
96+
},
97+
"item": [
98+
{
99+
"href": "http:\/\/example.com\/absolute_url_dummies\/1"
100+
}
101+
]
102+
},
103+
"totalItems": 1,
104+
"itemsPerPage": 3,
105+
"_embedded": {
106+
"item": [
107+
{
108+
"_links": {
109+
"self": {
110+
"href": "http:\/\/example.com\/absolute_url_dummies\/1"
111+
},
112+
"absoluteUrlRelationDummy": {
113+
"href": "http:\/\/example.com\/absolute_url_relation_dummies\/1"
114+
}
115+
},
116+
"id": 1
117+
}
118+
]
119+
}
120+
}
121+
"""
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@absoluteUrl
2+
Feature: Check the Entrypoint with Absolute URLs
3+
4+
Scenario: Retrieve the API Entrypoint
5+
And I add "Accept" header equal to "application/hal+json"
6+
And I add "Content-Type" header equal to "application/json"
7+
And I send a "GET" request to "/"
8+
And the JSON nodes should be equal to:
9+
| _links.self.href | http://example.com/ |
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
@absoluteUrl
2+
Feature: IRI should contain Absolute URL
3+
In order to add detail to IRIs
4+
Include the absolute url
5+
6+
@createSchema
7+
Scenario: I should be able to GET a collection of Objects with Absolute Urls
8+
Given there are 1 absoluteUrlDummy objects with a related absoluteUrlRelationDummy
9+
And I add "Accept" header equal to "application/vnd.api+json"
10+
And I add "Content-Type" header equal to "application/json"
11+
And I send a "GET" request to "/absolute_url_dummies"
12+
And the JSON should be equal to:
13+
"""
14+
{
15+
"links": {
16+
"self": "http:\/\/example.com\/absolute_url_dummies"
17+
},
18+
"meta": {
19+
"totalItems": 1,
20+
"itemsPerPage": 3,
21+
"currentPage": 1
22+
},
23+
"data": [
24+
{
25+
"id": "http:\/\/example.com\/absolute_url_dummies\/1",
26+
"type": "AbsoluteUrlDummy",
27+
"attributes": {
28+
"_id": 1
29+
},
30+
"relationships": {
31+
"absoluteUrlRelationDummy": {
32+
"data": {
33+
"type": "AbsoluteUrlRelationDummy",
34+
"id": "http:\/\/example.com\/absolute_url_relation_dummies\/1"
35+
}
36+
}
37+
}
38+
}
39+
]
40+
}
41+
"""
42+
43+
Scenario: I should be able to POST an object using an Absolute Url
44+
Given I add "Accept" header equal to "application/vnd.api+json"
45+
And I add "Content-Type" header equal to "application/json"
46+
And I send a "POST" request to "/absolute_url_relation_dummies" with body:
47+
"""
48+
{
49+
"absolute_url_dummies": "http://example.com/absolute_url_dummies/1"
50+
}
51+
"""
52+
Then the response status code should be 201
53+
And the JSON should be equal to:
54+
"""
55+
{
56+
"data": {
57+
"id": "http:\/\/example.com\/absolute_url_relation_dummies\/2",
58+
"type": "AbsoluteUrlRelationDummy",
59+
"attributes": {
60+
"_id": 2
61+
}
62+
}
63+
}
64+
"""
65+
66+
Scenario: I should be able to GET an Item with Absolute Urls
67+
Given I add "Accept" header equal to "application/vnd.api+json"
68+
And I add "Content-Type" header equal to "application/json"
69+
And I send a "GET" request to "/absolute_url_dummies/1"
70+
And the JSON should be equal to:
71+
"""
72+
{
73+
"data": {
74+
"id": "http:\/\/example.com\/absolute_url_dummies\/1",
75+
"type": "AbsoluteUrlDummy",
76+
"attributes": {
77+
"_id": 1
78+
},
79+
"relationships": {
80+
"absoluteUrlRelationDummy": {
81+
"data": {
82+
"type": "AbsoluteUrlRelationDummy",
83+
"id": "http:\/\/example.com\/absolute_url_relation_dummies\/1"
84+
}
85+
}
86+
}
87+
}
88+
}
89+
"""
90+
91+
Scenario: I should be able to GET subresources with Absolute Urls
92+
Given I add "Accept" header equal to "application/vnd.api+json"
93+
And I add "Content-Type" header equal to "application/json"
94+
And I send a "GET" request to "/absolute_url_relation_dummies/1/absolute_url_dummies"
95+
And the JSON should be equal to:
96+
"""
97+
{
98+
"links": {
99+
"self": "http:\/\/example.com\/absolute_url_relation_dummies\/1\/absolute_url_dummies"
100+
},
101+
"meta": {
102+
"totalItems": 1,
103+
"itemsPerPage": 3,
104+
"currentPage": 1
105+
},
106+
"data": [
107+
{
108+
"id": "http:\/\/example.com\/absolute_url_dummies\/1",
109+
"type": "AbsoluteUrlDummy",
110+
"attributes": {
111+
"_id": 1
112+
},
113+
"relationships": {
114+
"absoluteUrlRelationDummy": {
115+
"data": {
116+
"type": "AbsoluteUrlRelationDummy",
117+
"id": "http:\/\/example.com\/absolute_url_relation_dummies\/1"
118+
}
119+
}
120+
}
121+
}
122+
]
123+
}
124+
"""
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@absoluteUrl
2+
Feature: Check the Entrypoint with Absolute URLs
3+
4+
Scenario: Retrieve the API Entrypoint
5+
And I add "Accept" header equal to "application/hal+json"
6+
And I add "Content-Type" header equal to "application/json"
7+
And I send a "GET" request to "/"
8+
And the JSON nodes should be equal to:
9+
| _links.self.href | http://example.com/ |

features/absolute_url/absolute_url.feature renamed to features/absolute_url/jsonld/absolute_url.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Feature: IRI should contain Absolute URL
1212
And the JSON should be equal to:
1313
"""
1414
{
15-
"@context": "\/contexts\/AbsoluteUrlDummy",
15+
"@context": "http:\/\/example.com\/contexts\/AbsoluteUrlDummy",
1616
"@id": "http:\/\/example.com\/absolute_url_dummies",
1717
"@type": "hydra:Collection",
1818
"hydra:member": [
@@ -41,7 +41,7 @@ Feature: IRI should contain Absolute URL
4141
And the JSON should be equal to:
4242
"""
4343
{
44-
"@context": "\/contexts\/AbsoluteUrlRelationDummy",
44+
"@context": "http:\/\/example.com\/contexts\/AbsoluteUrlRelationDummy",
4545
"@id": "http:\/\/example.com\/absolute_url_relation_dummies\/2",
4646
"@type": "AbsoluteUrlRelationDummy",
4747
"absoluteUrlDummies": [],
@@ -57,7 +57,7 @@ Feature: IRI should contain Absolute URL
5757
And the JSON should be equal to:
5858
"""
5959
{
60-
"@context": "\/contexts\/AbsoluteUrlDummy",
60+
"@context": "http:\/\/example.com\/contexts\/AbsoluteUrlDummy",
6161
"@id": "http:\/\/example.com\/absolute_url_dummies\/1",
6262
"@type": "AbsoluteUrlDummy",
6363
"absoluteUrlRelationDummy": "http:\/\/example.com\/absolute_url_relation_dummies\/1",
@@ -73,7 +73,7 @@ Feature: IRI should contain Absolute URL
7373
And the JSON should be equal to:
7474
"""
7575
{
76-
"@context": "\/contexts\/AbsoluteUrlDummy",
76+
"@context": "http:\/\/example.com\/contexts\/AbsoluteUrlDummy",
7777
"@id": "http:\/\/example.com\/absolute_url_relation_dummies\/1\/absolute_url_dummies",
7878
"@type": "hydra:Collection",
7979
"hydra:member": [
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@absoluteUrl
2+
Feature: Check the Entrypoint with Absolute URLs
3+
4+
Scenario: Retrieve the API Entrypoint
5+
And I add "Accept" header equal to "application/ld+json"
6+
And I add "Content-Type" header equal to "application/json"
7+
And I send a "GET" request to "/"
8+
And the JSON nodes should be equal to:
9+
| @context | http://example.com/contexts/Entrypoint |
10+
| @id | http://example.com/ |
11+
| @type | Entrypoint |

src/Bridge/Symfony/Bundle/Resources/config/api.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
<service id="api_platform.router" class="ApiPlatform\Core\Bridge\Symfony\Routing\Router" public="false">
5454
<argument type="service" id="router" />
55+
<argument>%api_platform.absolute_url%</argument>
5556
</service>
5657

5758
<service id="api_platform.iri_converter" class="ApiPlatform\Core\Bridge\Symfony\Routing\IriConverter" public="false">

src/Bridge/Symfony/Bundle/Resources/config/hal.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<service id="api_platform.hal.normalizer.collection" class="ApiPlatform\Core\Hal\Serializer\CollectionNormalizer" public="false">
2323
<argument type="service" id="api_platform.resource_class_resolver" />
2424
<argument>%api_platform.collection.pagination.page_parameter_name%</argument>
25+
<argument>%api_platform.absolute_url%</argument>
2526

2627
<!-- Run after api_platform.hal.normalizer.object but before serializer.normalizer.object and serializer.denormalizer.array -->
2728
<tag name="serializer.normalizer" priority="-985" />

src/Bridge/Symfony/Bundle/Resources/config/jsonapi.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<service id="api_platform.jsonapi.normalizer.collection" class="ApiPlatform\Core\JsonApi\Serializer\CollectionNormalizer" public="false">
2727
<argument type="service" id="api_platform.resource_class_resolver" />
2828
<argument>%api_platform.collection.pagination.page_parameter_name%</argument>
29+
<argument>%api_platform.absolute_url%</argument>
2930

3031
<!-- Run after api_platform.jsonapi.normalizer.object but before serializer.normalizer.object and serializer.denormalizer.array -->
3132
<tag name="serializer.normalizer" priority="-985" />

0 commit comments

Comments
 (0)