Skip to content

Commit 1bda3d4

Browse files
committed
Merge branch 'lazebnyi/add-array-items-handling-to-dynamic-schemas' of github.com:airbytehq/airbyte-python-cdk into lazebnyi/add-array-items-handling-to-dynamic-schemas
2 parents 73bda55 + 6682d9f commit 1bda3d4

File tree

4 files changed

+39
-71
lines changed

4 files changed

+39
-71
lines changed

airbyte_cdk/sources/declarative/models/declarative_component_schema.py

Lines changed: 32 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,7 @@ class OAuthAuthenticator(BaseModel):
604604
scopes: Optional[List[str]] = Field(
605605
None,
606606
description="List of scopes that should be granted to the access token.",
607-
examples=[
608-
["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]
609-
],
607+
examples=[["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]],
610608
title="Scopes",
611609
)
612610
token_expiry_date: Optional[str] = Field(
@@ -1042,28 +1040,24 @@ class OAuthConfigSpecification(BaseModel):
10421040
class Config:
10431041
extra = Extra.allow
10441042

1045-
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = (
1046-
Field(
1047-
None,
1048-
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 }",
1049-
examples=[
1050-
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1051-
{
1052-
"app_id": {
1053-
"type": "string",
1054-
"path_in_connector_config": ["info", "app_id"],
1055-
}
1056-
},
1057-
],
1058-
title="OAuth user input",
1059-
)
1043+
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = Field(
1044+
None,
1045+
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 }",
1046+
examples=[
1047+
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1048+
{
1049+
"app_id": {
1050+
"type": "string",
1051+
"path_in_connector_config": ["info", "app_id"],
1052+
}
1053+
},
1054+
],
1055+
title="OAuth user input",
10601056
)
1061-
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = (
1062-
Field(
1063-
None,
1064-
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 }',
1065-
title="DeclarativeOAuth Connector Specification",
1066-
)
1057+
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = Field(
1058+
None,
1059+
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 }',
1060+
title="DeclarativeOAuth Connector Specification",
10671061
)
10681062
complete_oauth_output_specification: Optional[Dict[str, Any]] = Field(
10691063
None,
@@ -1081,9 +1075,7 @@ class Config:
10811075
complete_oauth_server_input_specification: Optional[Dict[str, Any]] = Field(
10821076
None,
10831077
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 }",
1084-
examples=[
1085-
{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}
1086-
],
1078+
examples=[{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}],
10871079
title="OAuth input specification",
10881080
)
10891081
complete_oauth_server_output_specification: Optional[Dict[str, Any]] = Field(
@@ -1669,9 +1661,7 @@ class RecordSelector(BaseModel):
16691661
description="Responsible for filtering records to be emitted by the Source.",
16701662
title="Record Filter",
16711663
)
1672-
schema_normalization: Optional[
1673-
Union[SchemaNormalization, CustomSchemaNormalization]
1674-
] = Field(
1664+
schema_normalization: Optional[Union[SchemaNormalization, CustomSchemaNormalization]] = Field(
16751665
SchemaNormalization.None_,
16761666
description="Responsible for normalization according to the schema.",
16771667
title="Schema Normalization",
@@ -1845,16 +1835,12 @@ class Config:
18451835
description="Component used to coordinate how records are extracted across stream slices and request pages.",
18461836
title="Retriever",
18471837
)
1848-
incremental_sync: Optional[Union[CustomIncrementalSync, DatetimeBasedCursor]] = (
1849-
Field(
1850-
None,
1851-
description="Component used to fetch data incrementally based on a time field in the data.",
1852-
title="Incremental Sync",
1853-
)
1854-
)
1855-
name: Optional[str] = Field(
1856-
"", description="The stream name.", example=["Users"], title="Name"
1838+
incremental_sync: Optional[Union[CustomIncrementalSync, DatetimeBasedCursor]] = Field(
1839+
None,
1840+
description="Component used to fetch data incrementally based on a time field in the data.",
1841+
title="Incremental Sync",
18571842
)
1843+
name: Optional[str] = Field("", description="The stream name.", example=["Users"], title="Name")
18581844
primary_key: Optional[PrimaryKey] = Field(
18591845
"", description="The primary key of the stream.", title="Primary Key"
18601846
)
@@ -2126,11 +2112,7 @@ class SimpleRetriever(BaseModel):
21262112
CustomPartitionRouter,
21272113
ListPartitionRouter,
21282114
SubstreamPartitionRouter,
2129-
List[
2130-
Union[
2131-
CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter
2132-
]
2133-
],
2115+
List[Union[CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter]],
21342116
]
21352117
] = Field(
21362118
[],
@@ -2174,9 +2156,7 @@ class AsyncRetriever(BaseModel):
21742156
)
21752157
download_extractor: Optional[
21762158
Union[CustomRecordExtractor, DpathExtractor, ResponseToFileExtractor]
2177-
] = Field(
2178-
None, description="Responsible for fetching the records from provided urls."
2179-
)
2159+
] = Field(None, description="Responsible for fetching the records from provided urls.")
21802160
creation_requester: Union[CustomRequester, HttpRequester] = Field(
21812161
...,
21822162
description="Requester component that describes how to prepare HTTP requests to send to the source API to create the async server-side job.",
@@ -2210,11 +2190,7 @@ class AsyncRetriever(BaseModel):
22102190
CustomPartitionRouter,
22112191
ListPartitionRouter,
22122192
SubstreamPartitionRouter,
2213-
List[
2214-
Union[
2215-
CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter
2216-
]
2217-
],
2193+
List[Union[CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter]],
22182194
]
22192195
] = Field(
22202196
[],
@@ -2282,12 +2258,10 @@ class DynamicDeclarativeStream(BaseModel):
22822258
stream_template: DeclarativeStream = Field(
22832259
..., description="Reference to the stream template.", title="Stream Template"
22842260
)
2285-
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = (
2286-
Field(
2287-
...,
2288-
description="Component resolve and populates stream templates with components values.",
2289-
title="Components Resolver",
2290-
)
2261+
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = Field(
2262+
...,
2263+
description="Component resolve and populates stream templates with components values.",
2264+
title="Components Resolver",
22912265
)
22922266

22932267

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@
133133
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
134134
CheckStream as CheckStreamModel,
135135
)
136+
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
137+
ComplexFieldType as ComplexFieldTypeModel,
138+
)
136139
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
137140
ComponentMappingDefinition as ComponentMappingDefinitionModel,
138141
)
@@ -244,9 +247,6 @@
244247
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
245248
InlineSchemaLoader as InlineSchemaLoaderModel,
246249
)
247-
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
248-
ComplexFieldType as ComplexFieldTypeModel,
249-
)
250250
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
251251
IterableDecoder as IterableDecoderModel,
252252
)
@@ -432,10 +432,10 @@
432432
SimpleRetrieverTestReadDecorator,
433433
)
434434
from airbyte_cdk.sources.declarative.schema import (
435+
ComplexFieldType,
435436
DefaultSchemaLoader,
436437
DynamicSchemaLoader,
437438
InlineSchemaLoader,
438-
ComplexFieldType,
439439
JsonFileSchemaLoader,
440440
SchemaTypeIdentifier,
441441
TypesMap,

airbyte_cdk/sources/declarative/schema/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
from airbyte_cdk.sources.declarative.schema.default_schema_loader import DefaultSchemaLoader
66
from airbyte_cdk.sources.declarative.schema.dynamic_schema_loader import (
7+
ComplexFieldType,
78
DynamicSchemaLoader,
89
SchemaTypeIdentifier,
9-
ComplexFieldType,
1010
TypesMap,
1111
)
1212
from airbyte_cdk.sources.declarative.schema.inline_schema_loader import InlineSchemaLoader

unit_tests/sources/declarative/schema/test_dynamic_schema_loader.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,9 @@
8585
"key_pointer": ["name"],
8686
"type_pointer": ["type"],
8787
"types_mapping": [
88+
{"target_type": "string", "current_type": "singleLineText"},
8889
{
89-
"target_type": "string",
90-
"current_type": "singleLineText"
91-
},
92-
{
93-
"target_type": {
94-
"field_type": "array",
95-
"items": "integer"
96-
},
90+
"target_type": {"field_type": "array", "items": "integer"},
9791
"current_type": "formula",
9892
"condition": "{{ raw_schema['result']['type'] == 'customInteger' }}",
9993
},

0 commit comments

Comments
 (0)