Skip to content

Commit 495bf2b

Browse files
committed
include object links from extensions in list of hierarchical link rel types
1 parent 9db7bf8 commit 495bf2b

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

pystac/link.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from copy import copy
22

3+
import pystac
34
from pystac import STACError
45
from pystac.stac_io import STAC_IO
56
from pystac.utils import (make_absolute_href, make_relative_href, is_absolute_href)
@@ -81,12 +82,14 @@ def get_href(self):
8182
else:
8283
href = self.target
8384

84-
# if a hierarchical link with an owner and root, and relative catalog
85-
if self.rel in HIERARCHICAL_LINKS and self.owner is not None:
86-
root = self.owner.get_root()
87-
if root is not None and root.catalog_type in ['RELATIVE_PUBLISHED', 'SELF_CONTAINED']:
88-
if href and is_absolute_href(href):
89-
href = make_relative_href(href, self.owner.get_self_href())
85+
if href and self.owner is not None:
86+
rel_links = HIERARCHICAL_LINKS + pystac.STAC_EXTENSIONS.get_extended_object_links(self.owner)
87+
# if a hierarchical link with an owner and root, and relative catalog
88+
if self.rel in rel_links:
89+
root = self.owner.get_root()
90+
if root is not None and root.catalog_type in ['RELATIVE_PUBLISHED', 'SELF_CONTAINED']:
91+
if href and is_absolute_href(href):
92+
href = make_relative_href(href, self.owner.get_self_href())
9093

9194
return href
9295

tests/test_writing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
from tempfile import TemporaryDirectory
33

4+
import pystac
45
from pystac import (STAC_IO, STACObject, Collection, CatalogType, HIERARCHICAL_LINKS)
56
from pystac.serialization import (STACObjectType)
67
from pystac.utils import is_absolute_href, make_absolute_href, make_relative_href
@@ -46,9 +47,10 @@ def validate_asset_href_type(item, item_href, link_type):
4647
def validate_item_link_type(href, link_type, should_include_self):
4748
item_dict = STAC_IO.read_json(href)
4849
item = STACObject.from_file(href)
50+
rel_links = HIERARCHICAL_LINKS + pystac.STAC_EXTENSIONS.get_extended_object_links(item)
4951
for link in item.get_links():
5052
if not link.rel == 'self':
51-
if link_type == 'RELATIVE' and link.rel in HIERARCHICAL_LINKS:
53+
if link_type == 'RELATIVE' and link.rel in rel_links:
5254
self.assertFalse(is_absolute_href(link.get_href()))
5355
else:
5456
self.assertTrue(is_absolute_href(link.get_href()))

0 commit comments

Comments
 (0)