Skip to content

Commit c403a0e

Browse files
author
Oleksandr Bazarnov
committed
rename sharable > linkable, shared > linked
1 parent 9de27ef commit c403a0e

File tree

4 files changed

+81
-80
lines changed

4 files changed

+81
-80
lines changed

airbyte_cdk/sources/declarative/declarative_component_schema.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,7 @@ definitions:
18691869
type: string
18701870
enum: [HttpRequester]
18711871
url_base:
1872-
sharable: true
1872+
linkable: true
18731873
title: API Base URL
18741874
description: The Base URL of the API source. Do not put sensitive information (e.g. API tokens) into this field - Use the Authentication component for this.
18751875
type: string
@@ -1905,7 +1905,7 @@ definitions:
19051905
- "/quotes/{{ stream_partition['id'] }}/quote_line_groups"
19061906
- "/trades/{{ config['symbol_id'] }}/history"
19071907
authenticator:
1908-
sharable: true
1908+
linkable: true
19091909
title: Authenticator
19101910
description: Authentication method to use for requests sent to the API.
19111911
anyOf:

airbyte_cdk/sources/declarative/parsers/manifest_normalizer.py

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,53 +19,54 @@
1919

2020
# Configuration constants
2121
N_OCCURANCES = 2
22+
2223
DEF_TAG = "definitions"
23-
STREAMS_TAG = "streams"
24-
SHARED_TAG = "shared"
25-
SHARABLE_TAG = "sharable"
24+
LINKABLE_TAG = "linkable"
25+
LINKED_TAG = "linked"
26+
PROPERTIES_TAG = "properties"
2627
SCHEMA_LOADER_TAG = "schema_loader"
27-
SCHEMAS_TAG = "schemas"
2828
SCHEMA_TAG = "schema"
29-
PROPERTIES_TAG = "properties"
29+
SCHEMAS_TAG = "schemas"
30+
STREAMS_TAG = "streams"
3031

3132

32-
def _get_sharable_schema_tags(schema: DefinitionsType) -> List[str]:
33+
def _get_linkable_schema_tags(schema: DefinitionsType) -> List[str]:
3334
"""
34-
Extracts sharable tags from schema definitions.
35-
This function identifies properties within a schema's definitions that are marked as sharable.
35+
Extracts linkable tags from schema definitions.
36+
This function identifies properties within a schema's definitions that are marked as linkable.
3637
It traverses through each definition in the schema, examines its properties, and collects
37-
the keys of properties that contain the SHARABLE_TAG.
38+
the keys of properties that contain the LINKABLE_TAG.
3839
3940
Args:
4041
schema (DefinitionsType): The schema definition dictionary to process
4142
4243
Returns:
43-
List[str]: A deduplicated list of property keys that are marked as sharable
44+
List[str]: A deduplicated list of property keys that are marked as linkable
4445
"""
4546

46-
# the sharable scope: ['definitions.*']
47+
# the linkable scope: ['definitions.*']
4748
schema_definitions = schema.get(DEF_TAG, {})
4849

49-
sharable_tags: List[str] = []
50-
# Extract sharable keys from properties
50+
linkable_tags: List[str] = []
51+
# Extract linkable keys from properties
5152

52-
extract_sharable_keys: Callable[[Dict[str, Dict[str, Any]]], List[str]] = lambda properties: [
53-
key for key, value in properties.items() if SHARABLE_TAG in value.keys()
53+
extract_linkable_keys: Callable[[Dict[str, Dict[str, Any]]], List[str]] = lambda properties: [
54+
key for key, value in properties.items() if LINKABLE_TAG in value.keys()
5455
]
5556

56-
# Process each root value to get its sharable keys
57-
process_root: Callable[[Dict[str, Any]], List[str]] = lambda root_value: extract_sharable_keys(
57+
# Process each root value to get its linkable keys
58+
process_root: Callable[[Dict[str, Any]], List[str]] = lambda root_value: extract_linkable_keys(
5859
root_value.get(PROPERTIES_TAG, {})
5960
)
6061

6162
# Map the process_root function over all schema values and flatten the results
62-
all_sharable_tags = chain.from_iterable(map(process_root, schema_definitions.values()))
63+
all_linkable_tags = chain.from_iterable(map(process_root, schema_definitions.values()))
6364

64-
# Add all found sharable tags to the tags list
65-
sharable_tags.extend(all_sharable_tags)
65+
# Add all found linkable tags to the tags list
66+
linkable_tags.extend(all_linkable_tags)
6667

6768
# return unique tags only
68-
return list(set(sharable_tags))
69+
return list(set(linkable_tags))
6970

7071

7172
class ManifestNormalizer:
@@ -85,8 +86,8 @@ def __init__(
8586
self._resolved_manifest = resolved_manifest
8687
self._declarative_schema = declarative_schema
8788
self._normalized_manifest: ManifestType = copy.deepcopy(self._resolved_manifest)
88-
# get the tags marked as `sharable` in the component schema
89-
self._sharable_tags = _get_sharable_schema_tags(self._declarative_schema)
89+
# get the tags marked as `linkable` in the component schema
90+
self._linkable_tags = _get_linkable_schema_tags(self._declarative_schema)
9091

9192
def to_json_str(self) -> str:
9293
return json.dumps(self._normalized_manifest, indent=2)
@@ -152,13 +153,13 @@ def _prepare_definitions(self) -> None:
152153
if not DEF_TAG in self._normalized_manifest:
153154
self._normalized_manifest[DEF_TAG] = {}
154155

155-
# Check if the shared tag exists
156-
if not SHARED_TAG in self._normalized_manifest[DEF_TAG]:
157-
self._normalized_manifest[DEF_TAG][SHARED_TAG] = {}
156+
# Check if the linked tag exists
157+
if not LINKED_TAG in self._normalized_manifest[DEF_TAG]:
158+
self._normalized_manifest[DEF_TAG][LINKED_TAG] = {}
158159

159-
# remove everything from definitions tag except of `shared`, after processing
160+
# remove everything from definitions tag except of `linked`, after processing
160161
for key in list(self._normalized_manifest[DEF_TAG].keys()):
161-
if key != SHARED_TAG:
162+
if key != LINKED_TAG:
162163
self._normalized_manifest[DEF_TAG].pop(key, None)
163164

164165
def _reference_schemas(self) -> None:
@@ -189,19 +190,19 @@ def _replace_duplicates_with_refs(self, duplicates: DuplicatesType) -> None:
189190

190191
for _, occurrences in duplicates.items():
191192
type_key, key, value = self._get_occurance_samples(occurrences)
192-
is_shared_def = self._is_shared_definition(type_key, key)
193+
is_linked_def = self._is_linked_definition(type_key, key)
193194

194195
# Add to definitions if not there already
195-
if not is_shared_def:
196-
self._add_to_shared_definitions(type_key, key, value)
196+
if not is_linked_def:
197+
self._add_to_linked_definitions(type_key, key, value)
197198

198199
# Replace occurrences with references
199200
for _, parent_obj, value in occurrences:
200-
if is_shared_def:
201-
if value == self._get_shared_definition_value(type_key, key):
202-
parent_obj[key] = self._create_shared_definition_ref(type_key, key)
201+
if is_linked_def:
202+
if value == self._get_linked_definition_value(type_key, key):
203+
parent_obj[key] = self._create_linked_definition_ref(type_key, key)
203204
else:
204-
parent_obj[key] = self._create_shared_definition_ref(type_key, key)
205+
parent_obj[key] = self._create_linked_definition_ref(type_key, key)
205206

206207
def _handle_duplicates(self, duplicates: DuplicatesType) -> None:
207208
"""
@@ -241,25 +242,25 @@ def _add_duplicate(
241242
value_to_hash = {key: value} if key is not None else value
242243
duplicates[self._hash_object(value_to_hash)].append((current_path, obj, value))
243244

244-
def _add_to_shared_definitions(
245+
def _add_to_linked_definitions(
245246
self,
246247
type_key: str,
247248
key: str,
248249
value: Any,
249250
) -> None:
250251
"""
251-
Add a value to the shared definitions under the specified key.
252+
Add a value to the linked definitions under the specified key.
252253
253254
Args:
254255
definitions: The definitions dictionary to modify
255256
key: The key to use
256257
value: The value to add
257258
"""
258-
if type_key not in self._normalized_manifest[DEF_TAG][SHARED_TAG].keys():
259-
self._normalized_manifest[DEF_TAG][SHARED_TAG][type_key] = {}
259+
if type_key not in self._normalized_manifest[DEF_TAG][LINKED_TAG].keys():
260+
self._normalized_manifest[DEF_TAG][LINKED_TAG][type_key] = {}
260261

261-
if key not in self._normalized_manifest[DEF_TAG][SHARED_TAG][type_key].keys():
262-
self._normalized_manifest[DEF_TAG][SHARED_TAG][type_key][key] = value
262+
if key not in self._normalized_manifest[DEF_TAG][LINKED_TAG][type_key].keys():
263+
self._normalized_manifest[DEF_TAG][LINKED_TAG][type_key][key] = value
263264

264265
def _collect_duplicates(self) -> DuplicatesType:
265266
"""
@@ -297,13 +298,13 @@ def _collect(obj: Dict[str, Any], path: Optional[List[str]] = None) -> None:
297298
# First process nested dictionaries
298299
_collect(value, current_path)
299300
# Process allowed-only component tags
300-
if key in self._sharable_tags:
301+
if key in self._linkable_tags:
301302
self._add_duplicate(duplicates, current_path, obj, value)
302303

303304
# handle primitive types
304305
elif isinstance(value, (str, int, float, bool)):
305306
# Process allowed-only field tags
306-
if key in self._sharable_tags:
307+
if key in self._linkable_tags:
307308
self._add_duplicate(duplicates, current_path, obj, value, key)
308309

309310
# handle list cases
@@ -313,7 +314,7 @@ def _collect(obj: Dict[str, Any], path: Optional[List[str]] = None) -> None:
313314

314315
duplicates: DuplicatesType = defaultdict(list, {})
315316
try:
316-
if self._sharable_tags:
317+
if self._linkable_tags:
317318
_collect(self._normalized_manifest)
318319
# clean non-duplicates and sort based on the count of occurrences
319320
return self._clean_and_sort_duplicates(duplicates)
@@ -360,42 +361,42 @@ def _hash_object(self, obj: Dict[str, Any]) -> str:
360361
# Sort keys to ensure consistent hash for same content
361362
return hashlib.md5(json.dumps(obj, sort_keys=True).encode()).hexdigest()
362363

363-
def _is_shared_definition(self, type_key: str, key: str) -> bool:
364+
def _is_linked_definition(self, type_key: str, key: str) -> bool:
364365
"""
365-
Check if the key already exists in the shared definitions.
366+
Check if the key already exists in the linked definitions.
366367
367368
Args:
368369
key: The key to check
369370
definitions: The definitions dictionary with definitions
370371
371372
Returns:
372-
True if the key exists in the shared definitions, False otherwise
373+
True if the key exists in the linked definitions, False otherwise
373374
"""
374375

375-
if type_key in self._normalized_manifest[DEF_TAG][SHARED_TAG].keys():
376-
# Check if the key exists in the shared definitions
377-
if key in self._normalized_manifest[DEF_TAG][SHARED_TAG][type_key].keys():
376+
if type_key in self._normalized_manifest[DEF_TAG][LINKED_TAG].keys():
377+
# Check if the key exists in the linked definitions
378+
if key in self._normalized_manifest[DEF_TAG][LINKED_TAG][type_key].keys():
378379
return True
379380

380381
return False
381382

382-
def _get_shared_definition_value(self, type_key: str, key: str) -> Any:
383+
def _get_linked_definition_value(self, type_key: str, key: str) -> Any:
383384
"""
384-
Get the value of a shared definition by its key.
385+
Get the value of a linked definition by its key.
385386
386387
Args:
387388
key: The key to check
388389
definitions: The definitions dictionary with definitions
389390
390391
Returns:
391-
The value of the shared definition
392+
The value of the linked definition
392393
"""
393-
if type_key in self._normalized_manifest[DEF_TAG][SHARED_TAG].keys():
394-
if key in self._normalized_manifest[DEF_TAG][SHARED_TAG][type_key].keys():
395-
return self._normalized_manifest[DEF_TAG][SHARED_TAG][type_key][key]
394+
if type_key in self._normalized_manifest[DEF_TAG][LINKED_TAG].keys():
395+
if key in self._normalized_manifest[DEF_TAG][LINKED_TAG][type_key].keys():
396+
return self._normalized_manifest[DEF_TAG][LINKED_TAG][type_key][key]
396397
else:
397398
raise ManifestNormalizationException(
398-
f"Key {key} not found in shared definitions. Please check the manifest."
399+
f"Key {key} not found in linked definitions. Please check the manifest."
399400
)
400401

401402
def _get_occurance_samples(self, occurrences: DuplicateOccurancesType) -> Tuple[str, str, Any]:
@@ -417,9 +418,9 @@ def _get_occurance_samples(self, occurrences: DuplicateOccurancesType) -> Tuple[
417418
value,
418419
) # Return the component's name as the last part of its path
419420

420-
def _create_shared_definition_ref(self, type_key: str, key: str) -> Dict[str, str]:
421+
def _create_linked_definition_ref(self, type_key: str, key: str) -> Dict[str, str]:
421422
"""
422-
Create a reference object for the shared definitions using the specified key.
423+
Create a reference object for the linked definitions using the specified key.
423424
424425
Args:
425426
ref_key: The reference key to use
@@ -428,7 +429,7 @@ def _create_shared_definition_ref(self, type_key: str, key: str) -> Dict[str, st
428429
A reference object in the proper format
429430
"""
430431

431-
return {"$ref": f"#/{DEF_TAG}/{SHARED_TAG}/{type_key}/{key}"}
432+
return {"$ref": f"#/{DEF_TAG}/{LINKED_TAG}/{type_key}/{key}"}
432433

433434
def _create_schema_ref(self, ref_key: str) -> Dict[str, str]:
434435
"""

0 commit comments

Comments
 (0)