Skip to content

Commit c932185

Browse files
committed
Add unittest
1 parent 89066c8 commit c932185

File tree

4 files changed

+148
-105
lines changed

4 files changed

+148
-105
lines changed

airbyte_cdk/sources/declarative/declarative_component_schema.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4050,7 +4050,7 @@ definitions:
40504050
- ["data", "{{ parameters.name }}"]
40514051
default_values:
40524052
title: Default Values
4053-
description: placeholder
4053+
description: A list of default values, each matching the structure expected from the parsed component value.
40544054
type: array
40554055
items:
40564056
type: object

airbyte_cdk/sources/declarative/models/declarative_component_schema.py

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,9 @@ class OAuthAuthenticator(BaseModel):
618618
scopes: Optional[List[str]] = Field(
619619
None,
620620
description="List of scopes that should be granted to the access token.",
621-
examples=[["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]],
621+
examples=[
622+
["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]
623+
],
622624
title="Scopes",
623625
)
624626
token_expiry_date: Optional[str] = Field(
@@ -1124,24 +1126,28 @@ class OAuthConfigSpecification(BaseModel):
11241126
class Config:
11251127
extra = Extra.allow
11261128

1127-
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = Field(
1128-
None,
1129-
description="OAuth specific blob. This is a Json Schema used to validate Json configurations used as input to OAuth.\nMust be a valid non-nested JSON that refers to properties from ConnectorSpecification.connectionSpecification\nusing special annotation 'path_in_connector_config'.\nThese are input values the user is entering through the UI to authenticate to the connector, that might also shared\nas inputs for syncing data via the connector.\nExamples:\nif no connector values is shared during oauth flow, oauth_user_input_from_connector_config_specification=[]\nif connector values such as 'app_id' inside the top level are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['app_id']\n }\n }\nif connector values such as 'info.app_id' nested inside another object are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['info', 'app_id']\n }\n }",
1130-
examples=[
1131-
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1132-
{
1133-
"app_id": {
1134-
"type": "string",
1135-
"path_in_connector_config": ["info", "app_id"],
1136-
}
1137-
},
1138-
],
1139-
title="OAuth user input",
1129+
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = (
1130+
Field(
1131+
None,
1132+
description="OAuth specific blob. This is a Json Schema used to validate Json configurations used as input to OAuth.\nMust be a valid non-nested JSON that refers to properties from ConnectorSpecification.connectionSpecification\nusing special annotation 'path_in_connector_config'.\nThese are input values the user is entering through the UI to authenticate to the connector, that might also shared\nas inputs for syncing data via the connector.\nExamples:\nif no connector values is shared during oauth flow, oauth_user_input_from_connector_config_specification=[]\nif connector values such as 'app_id' inside the top level are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['app_id']\n }\n }\nif connector values such as 'info.app_id' nested inside another object are used to generate the API url for the oauth flow,\n oauth_user_input_from_connector_config_specification={\n app_id: {\n type: string\n path_in_connector_config: ['info', 'app_id']\n }\n }",
1133+
examples=[
1134+
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1135+
{
1136+
"app_id": {
1137+
"type": "string",
1138+
"path_in_connector_config": ["info", "app_id"],
1139+
}
1140+
},
1141+
],
1142+
title="OAuth user input",
1143+
)
11401144
)
1141-
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = Field(
1142-
None,
1143-
description='The DeclarativeOAuth specific blob.\nPertains to the fields defined by the connector relating to the OAuth flow.\n\nInterpolation capabilities:\n- The variables placeholders are declared as `{{my_var}}`.\n- The nested resolution variables like `{{ {{my_nested_var}} }}` is allowed as well.\n\n- The allowed interpolation context is:\n + base64Encoder - encode to `base64`, {{ {{my_var_a}}:{{my_var_b}} | base64Encoder }}\n + base64Decorer - decode from `base64` encoded string, {{ {{my_string_variable_or_string_value}} | base64Decoder }}\n + urlEncoder - encode the input string to URL-like format, {{ https://test.host.com/endpoint | urlEncoder}}\n + urlDecorer - decode the input url-encoded string into text format, {{ urlDecoder:https%3A%2F%2Fairbyte.io | urlDecoder}}\n + codeChallengeS256 - get the `codeChallenge` encoded value to provide additional data-provider specific authorisation values, {{ {{state_value}} | codeChallengeS256 }}\n\nExamples:\n - The TikTok Marketing DeclarativeOAuth spec:\n {\n "oauth_connector_input_specification": {\n "type": "object",\n "additionalProperties": false,\n "properties": {\n "consent_url": "https://ads.tiktok.com/marketing_api/auth?{{client_id_key}}={{client_id_value}}&{{redirect_uri_key}}={{ {{redirect_uri_value}} | urlEncoder}}&{{state_key}}={{state_value}}",\n "access_token_url": "https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/",\n "access_token_params": {\n "{{ auth_code_key }}": "{{ auth_code_value }}",\n "{{ client_id_key }}": "{{ client_id_value }}",\n "{{ client_secret_key }}": "{{ client_secret_value }}"\n },\n "access_token_headers": {\n "Content-Type": "application/json",\n "Accept": "application/json"\n },\n "extract_output": ["data.access_token"],\n "client_id_key": "app_id",\n "client_secret_key": "secret",\n "auth_code_key": "auth_code"\n }\n }\n }',
1144-
title="DeclarativeOAuth Connector Specification",
1145+
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = (
1146+
Field(
1147+
None,
1148+
description='The DeclarativeOAuth specific blob.\nPertains to the fields defined by the connector relating to the OAuth flow.\n\nInterpolation capabilities:\n- The variables placeholders are declared as `{{my_var}}`.\n- The nested resolution variables like `{{ {{my_nested_var}} }}` is allowed as well.\n\n- The allowed interpolation context is:\n + base64Encoder - encode to `base64`, {{ {{my_var_a}}:{{my_var_b}} | base64Encoder }}\n + base64Decorer - decode from `base64` encoded string, {{ {{my_string_variable_or_string_value}} | base64Decoder }}\n + urlEncoder - encode the input string to URL-like format, {{ https://test.host.com/endpoint | urlEncoder}}\n + urlDecorer - decode the input url-encoded string into text format, {{ urlDecoder:https%3A%2F%2Fairbyte.io | urlDecoder}}\n + codeChallengeS256 - get the `codeChallenge` encoded value to provide additional data-provider specific authorisation values, {{ {{state_value}} | codeChallengeS256 }}\n\nExamples:\n - The TikTok Marketing DeclarativeOAuth spec:\n {\n "oauth_connector_input_specification": {\n "type": "object",\n "additionalProperties": false,\n "properties": {\n "consent_url": "https://ads.tiktok.com/marketing_api/auth?{{client_id_key}}={{client_id_value}}&{{redirect_uri_key}}={{ {{redirect_uri_value}} | urlEncoder}}&{{state_key}}={{state_value}}",\n "access_token_url": "https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/",\n "access_token_params": {\n "{{ auth_code_key }}": "{{ auth_code_value }}",\n "{{ client_id_key }}": "{{ client_id_value }}",\n "{{ client_secret_key }}": "{{ client_secret_value }}"\n },\n "access_token_headers": {\n "Content-Type": "application/json",\n "Accept": "application/json"\n },\n "extract_output": ["data.access_token"],\n "client_id_key": "app_id",\n "client_secret_key": "secret",\n "auth_code_key": "auth_code"\n }\n }\n }',
1149+
title="DeclarativeOAuth Connector Specification",
1150+
)
11451151
)
11461152
complete_oauth_output_specification: Optional[Dict[str, Any]] = Field(
11471153
None,
@@ -1159,7 +1165,9 @@ class Config:
11591165
complete_oauth_server_input_specification: Optional[Dict[str, Any]] = Field(
11601166
None,
11611167
description="OAuth specific blob. This is a Json Schema used to validate Json configurations persisted as Airbyte Server configurations.\nMust be a valid non-nested JSON describing additional fields configured by the Airbyte Instance or Workspace Admins to be used by the\nserver when completing an OAuth flow (typically exchanging an auth code for refresh token).\nExamples:\n complete_oauth_server_input_specification={\n client_id: {\n type: string\n },\n client_secret: {\n type: string\n }\n }",
1162-
examples=[{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}],
1168+
examples=[
1169+
{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}
1170+
],
11631171
title="OAuth input specification",
11641172
)
11651173
complete_oauth_server_output_specification: Optional[Dict[str, Any]] = Field(
@@ -1491,7 +1499,9 @@ class StreamConfig(BaseModel):
14911499
title="Configs Pointer",
14921500
)
14931501
default_values: Optional[List[Dict[str, Any]]] = Field(
1494-
None, description="placeholder", title="Default Values"
1502+
None,
1503+
description="A list of default values, each matching the structure expected from the parsed component value.",
1504+
title="Default Values",
14951505
)
14961506
parameters: Optional[Dict[str, Any]] = Field(None, alias="$parameters")
14971507

@@ -1889,7 +1899,9 @@ class RecordSelector(BaseModel):
18891899
description="Responsible for filtering records to be emitted by the Source.",
18901900
title="Record Filter",
18911901
)
1892-
schema_normalization: Optional[Union[SchemaNormalization, CustomSchemaNormalization]] = Field(
1902+
schema_normalization: Optional[
1903+
Union[SchemaNormalization, CustomSchemaNormalization]
1904+
] = Field(
18931905
None,
18941906
description="Responsible for normalization according to the schema.",
18951907
title="Schema Normalization",
@@ -2135,7 +2147,9 @@ class Config:
21352147
extra = Extra.allow
21362148

21372149
type: Literal["DeclarativeStream"]
2138-
name: Optional[str] = Field("", description="The stream name.", example=["Users"], title="Name")
2150+
name: Optional[str] = Field(
2151+
"", description="The stream name.", example=["Users"], title="Name"
2152+
)
21392153
retriever: Union[SimpleRetriever, AsyncRetriever, CustomRetriever] = Field(
21402154
...,
21412155
description="Component used to coordinate how records are extracted across stream slices and request pages.",
@@ -2313,18 +2327,20 @@ class HttpRequester(BaseModelWithDeprecations):
23132327
description="Allows for retrieving a dynamic set of properties from an API endpoint which can be injected into outbound request using the stream_partition.extra_fields.",
23142328
title="Fetch Properties from Endpoint",
23152329
)
2316-
request_parameters: Optional[Union[Dict[str, Union[str, QueryProperties]], str]] = Field(
2317-
None,
2318-
description="Specifies the query parameters that should be set on an outgoing HTTP request given the inputs.",
2319-
examples=[
2320-
{"unit": "day"},
2321-
{
2322-
"query": 'last_event_time BETWEEN TIMESTAMP "{{ stream_interval.start_time }}" AND TIMESTAMP "{{ stream_interval.end_time }}"'
2323-
},
2324-
{"searchIn": "{{ ','.join(config.get('search_in', [])) }}"},
2325-
{"sort_by[asc]": "updated_at"},
2326-
],
2327-
title="Query Parameters",
2330+
request_parameters: Optional[Union[Dict[str, Union[str, QueryProperties]], str]] = (
2331+
Field(
2332+
None,
2333+
description="Specifies the query parameters that should be set on an outgoing HTTP request given the inputs.",
2334+
examples=[
2335+
{"unit": "day"},
2336+
{
2337+
"query": 'last_event_time BETWEEN TIMESTAMP "{{ stream_interval.start_time }}" AND TIMESTAMP "{{ stream_interval.end_time }}"'
2338+
},
2339+
{"searchIn": "{{ ','.join(config.get('search_in', [])) }}"},
2340+
{"sort_by[asc]": "updated_at"},
2341+
],
2342+
title="Query Parameters",
2343+
)
23282344
)
23292345
request_headers: Optional[Union[Dict[str, str], str]] = Field(
23302346
None,
@@ -2514,7 +2530,9 @@ class QueryProperties(BaseModel):
25142530

25152531
class StateDelegatingStream(BaseModel):
25162532
type: Literal["StateDelegatingStream"]
2517-
name: str = Field(..., description="The stream name.", example=["Users"], title="Name")
2533+
name: str = Field(
2534+
..., description="The stream name.", example=["Users"], title="Name"
2535+
)
25182536
full_refresh_stream: DeclarativeStream = Field(
25192537
...,
25202538
description="Component used to coordinate how records are extracted across stream slices and request pages when the state is empty or not provided.",
@@ -2603,7 +2621,9 @@ class AsyncRetriever(BaseModel):
26032621
)
26042622
download_extractor: Optional[
26052623
Union[DpathExtractor, CustomRecordExtractor, ResponseToFileExtractor]
2606-
] = Field(None, description="Responsible for fetching the records from provided urls.")
2624+
] = Field(
2625+
None, description="Responsible for fetching the records from provided urls."
2626+
)
26072627
creation_requester: Union[HttpRequester, CustomRequester] = Field(
26082628
...,
26092629
description="Requester component that describes how to prepare HTTP requests to send to the source API to create the async server-side job.",
@@ -2743,10 +2763,12 @@ class DynamicDeclarativeStream(BaseModel):
27432763
stream_template: DeclarativeStream = Field(
27442764
..., description="Reference to the stream template.", title="Stream Template"
27452765
)
2746-
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = Field(
2747-
...,
2748-
description="Component resolve and populates stream templates with components values.",
2749-
title="Components Resolver",
2766+
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = (
2767+
Field(
2768+
...,
2769+
description="Component resolve and populates stream templates with components values.",
2770+
title="Components Resolver",
2771+
)
27502772
)
27512773

27522774

airbyte_cdk/sources/declarative/resolvers/config_components_resolver.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,14 @@ def prepare_streams() -> Iterable[List[Tuple[int, Any]]]:
118118
"""
119119
for stream_config in self.stream_configs:
120120
path = resolve_path(stream_config.configs_pointer)
121-
stream_configs = dpath.get(dict(self.config), path, default=[])
121+
stream_configs_raw = dpath.get(dict(self.config), path, default=[])
122122
stream_configs = (
123-
stream_configs if isinstance(stream_configs, list) else [stream_configs]
123+
list(stream_configs_raw) if isinstance(stream_configs_raw, list) else [stream_configs_raw]
124124
)
125+
125126
if stream_config.default_values:
126127
stream_configs.extend(stream_config.default_values)
128+
127129
yield [(i, item) for i, item in enumerate(stream_configs)]
128130

129131
def merge_combination(combo: Iterable[Tuple[int, Any]]) -> Dict[str, Any]:

0 commit comments

Comments
 (0)