Skip to content

Commit 16b626c

Browse files
author
Dmytro
authored
Resolve discover catalog ref fields (#7734)
1 parent 109461b commit 16b626c

File tree

7 files changed

+20
-25
lines changed

7 files changed

+20
-25
lines changed

airbyte-cdk/python/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 0.1.33
4+
Resolve $ref fields for discover json schema.
5+
36
## 0.1.32
47
- Added Sphinx docs `airbyte-cdk/python/reference_docs` module.
58
- Added module documents at `airbyte-cdk/python/sphinx-docs.md`.

airbyte-cdk/python/airbyte_cdk/sources/utils/schema_helpers.py

+9-16
Original file line numberDiff line numberDiff line change
@@ -75,36 +75,29 @@ def __call__(self, uri: str) -> Dict[str, Any]:
7575
package = importlib.import_module(self.package_name)
7676
base = os.path.dirname(package.__file__) + "/"
7777

78-
def create_definitions(obj: dict, definitions: dict) -> Dict[str, Any]:
78+
def resolve_ref_links(obj: Any) -> Dict[str, Any]:
7979
"""
80-
Scan resolved schema and compose definitions section, also convert
81-
jsonref.JsonRef object to JSON serializable dict.
80+
Scan resolved schema and convert jsonref.JsonRef object to JSON
81+
serializable dict.
8282
8383
:param obj - jsonschema object with ref field resovled.
84-
:definitions - object for storing generated definitions.
8584
:return JSON serializable object with references without external dependencies.
8685
"""
8786
if isinstance(obj, jsonref.JsonRef):
88-
def_key = obj.__reference__["$ref"]
89-
def_key = def_key.replace("#/definitions/", "").replace(".json", "_")
90-
definition = create_definitions(obj.__subject__, definitions)
87+
obj = resolve_ref_links(obj.__subject__)
9188
# Omit existance definitions for extenal resource since
9289
# we dont need it anymore.
93-
definition.pop("definitions", None)
94-
definitions[def_key] = definition
95-
return {"$ref": "#/definitions/" + def_key}
90+
obj.pop("definitions", None)
91+
return obj
9692
elif isinstance(obj, dict):
97-
return {k: create_definitions(v, definitions) for k, v in obj.items()}
93+
return {k: resolve_ref_links(v) for k, v in obj.items()}
9894
elif isinstance(obj, list):
99-
return [create_definitions(item, definitions) for item in obj]
95+
return [resolve_ref_links(item) for item in obj]
10096
else:
10197
return obj
10298

10399
resolved = jsonref.JsonRef.replace_refs(raw_schema, loader=JsonFileLoader(base, "schemas/shared"), base_uri=base)
104-
definitions = {}
105-
resolved = create_definitions(resolved, definitions)
106-
if definitions:
107-
resolved["definitions"] = definitions
100+
resolved = resolve_ref_links(resolved)
108101
return resolved
109102

110103

airbyte-cdk/python/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
setup(
1717
name="airbyte-cdk",
18-
version="0.1.32",
18+
version="0.1.33",
1919
description="A framework for writing Airbyte Connectors.",
2020
long_description=README,
2121
long_description_content_type="text/markdown",

airbyte-cdk/python/unit_tests/sources/utils/test_schema_helpers.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ def test_shared_schemas_resolves():
9696
"properties": {
9797
"str": {"type": "string"},
9898
"int": {"type": "integer"},
99-
"obj": {"$ref": "#/definitions/shared_schema_"},
99+
"obj": {"type": ["null", "object"], "properties": {"k1": {"type": "string"}}},
100100
},
101-
"definitions": {"shared_schema_": {"type": ["null", "object"], "properties": {"k1": {"type": "string"}}}},
102101
}
103102

104103
partial_schema = {
@@ -123,10 +122,9 @@ def test_shared_schemas_resolves_nested():
123122
"properties": {
124123
"str": {"type": "string"},
125124
"int": {"type": "integer"},
126-
"one_of": {"oneOf": [{"type": "string"}, {"$ref": "#/definitions/shared_schema_type_one"}]},
127-
"obj": {"$ref": "#/definitions/shared_schema_type_one"},
125+
"one_of": {"oneOf": [{"type": "string"}, {"type": ["null", "object"], "properties": {"k1": {"type": "string"}}}]},
126+
"obj": {"type": ["null", "object"], "properties": {"k1": {"type": "string"}}},
128127
},
129-
"definitions": {"shared_schema_type_one": {"type": ["null", "object"], "properties": {"k1": {"type": "string"}}}},
130128
}
131129
partial_schema = {
132130
"type": ["null", "object"],

airbyte-integrations/connectors/source-facebook-marketing/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ RUN pip install .
1212
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
1313
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
1414

15-
LABEL io.airbyte.version=0.2.22
15+
LABEL io.airbyte.version=0.2.23
1616
LABEL io.airbyte.name=airbyte/source-facebook-marketing

airbyte-integrations/connectors/source-facebook-marketing/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from setuptools import find_packages, setup
77

88
MAIN_REQUIREMENTS = [
9-
"airbyte-cdk~=0.1.24",
9+
"airbyte-cdk~=0.1.33",
1010
"cached_property~=1.5",
1111
"facebook_business~=12.0",
1212
"pendulum>=2,<3",

docs/integrations/sources/facebook-marketing.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ As a summary, custom insights allows to replicate only some fields, resulting in
9696

9797
| Version | Date | Pull Request | Subject |
9898
| :--- | :--- | :--- | :--- |
99-
| 0.2.22 | 2021-11-05 | [4864](https://github.com/airbytehq/airbyte/pull/7605) | Add job retry logics to AdsInsights stream |
99+
| 0.2.23 | 2021-11-08 | [7734](https://github.com/airbytehq/airbyte/pull/7734) | Resolve $ref field for discover schema |
100+
| 0.2.22 | 2021-11-05 | [7605](https://github.com/airbytehq/airbyte/pull/7605) | Add job retry logics to AdsInsights stream |
100101
| 0.2.21 | 2021-10-05 | [4864](https://github.com/airbytehq/airbyte/pull/4864) | Update insights streams with custom entries for fields, breakdowns and action_breakdowns |
101102
| 0.2.20 | 2021-10-04 | [6719](https://github.com/airbytehq/airbyte/pull/6719) | Update version of facebook\_bussiness package to 12.0 |
102103
| 0.2.19 | 2021-09-30 | [6438](https://github.com/airbytehq/airbyte/pull/6438) | Annotate Oauth2 flow initialization parameters in connector specification |

0 commit comments

Comments
 (0)