Skip to content

Commit cc759dc

Browse files
committed
Add model
1 parent c89bc24 commit cc759dc

File tree

1 file changed

+70
-50
lines changed

1 file changed

+70
-50
lines changed

airbyte_cdk/sources/declarative/models/declarative_component_schema.py

Lines changed: 70 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,9 @@ class OAuthAuthenticator(BaseModel):
609609
scopes: Optional[List[str]] = Field(
610610
None,
611611
description="List of scopes that should be granted to the access token.",
612-
examples=[["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]],
612+
examples=[
613+
["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]
614+
],
613615
title="Scopes",
614616
)
615617
token_expiry_date: Optional[str] = Field(
@@ -1078,24 +1080,28 @@ class OAuthConfigSpecification(BaseModel):
10781080
class Config:
10791081
extra = Extra.allow
10801082

1081-
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = Field(
1082-
None,
1083-
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 }",
1084-
examples=[
1085-
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1086-
{
1087-
"app_id": {
1088-
"type": "string",
1089-
"path_in_connector_config": ["info", "app_id"],
1090-
}
1091-
},
1092-
],
1093-
title="OAuth user input",
1083+
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = (
1084+
Field(
1085+
None,
1086+
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 }",
1087+
examples=[
1088+
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1089+
{
1090+
"app_id": {
1091+
"type": "string",
1092+
"path_in_connector_config": ["info", "app_id"],
1093+
}
1094+
},
1095+
],
1096+
title="OAuth user input",
1097+
)
10941098
)
1095-
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = Field(
1096-
None,
1097-
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 }',
1098-
title="DeclarativeOAuth Connector Specification",
1099+
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = (
1100+
Field(
1101+
None,
1102+
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 }',
1103+
title="DeclarativeOAuth Connector Specification",
1104+
)
10991105
)
11001106
complete_oauth_output_specification: Optional[Dict[str, Any]] = Field(
11011107
None,
@@ -1113,7 +1119,9 @@ class Config:
11131119
complete_oauth_server_input_specification: Optional[Dict[str, Any]] = Field(
11141120
None,
11151121
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 }",
1116-
examples=[{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}],
1122+
examples=[
1123+
{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}
1124+
],
11171125
title="OAuth input specification",
11181126
)
11191127
complete_oauth_server_output_specification: Optional[Dict[str, Any]] = Field(
@@ -1427,6 +1435,10 @@ class ConfigComponentsResolver(BaseModel):
14271435
parameters: Optional[Dict[str, Any]] = Field(None, alias="$parameters")
14281436

14291437

1438+
class StateDelegatingRetriever(BaseModel):
1439+
__root__: Any
1440+
1441+
14301442
class AddedFieldDefinition(BaseModel):
14311443
type: Literal["AddedFieldDefinition"]
14321444
path: List[str] = Field(
@@ -1766,7 +1778,9 @@ class RecordSelector(BaseModel):
17661778
description="Responsible for filtering records to be emitted by the Source.",
17671779
title="Record Filter",
17681780
)
1769-
schema_normalization: Optional[Union[SchemaNormalization, CustomSchemaNormalization]] = Field(
1781+
schema_normalization: Optional[
1782+
Union[SchemaNormalization, CustomSchemaNormalization]
1783+
] = Field(
17701784
SchemaNormalization.None_,
17711785
description="Responsible for normalization according to the schema.",
17721786
title="Schema Normalization",
@@ -1860,7 +1874,7 @@ class Config:
18601874

18611875
type: Literal["DeclarativeSource"]
18621876
check: Union[CheckStream, CheckDynamicStream]
1863-
streams: List[DeclarativeStream]
1877+
streams: List[Union[DeclarativeStream, StateDelegatingStream]]
18641878
dynamic_streams: Optional[List[DynamicDeclarativeStream]] = None
18651879
version: str = Field(
18661880
...,
@@ -1887,7 +1901,7 @@ class Config:
18871901

18881902
type: Literal["DeclarativeSource"]
18891903
check: Union[CheckStream, CheckDynamicStream]
1890-
streams: Optional[List[DeclarativeStream]] = None
1904+
streams: Optional[List[Union[DeclarativeStream, StateDelegatingStream]]] = None
18911905
dynamic_streams: List[DynamicDeclarativeStream]
18921906
version: str = Field(
18931907
...,
@@ -1965,12 +1979,12 @@ class Config:
19651979
extra = Extra.allow
19661980

19671981
type: Literal["DeclarativeStream"]
1968-
retriever: Union[AsyncRetriever, CustomRetriever, SimpleRetriever, StateDelegatingRetriever] = (
1969-
Field(
1970-
...,
1971-
description="Component used to coordinate how records are extracted across stream slices and request pages.",
1972-
title="Retriever",
1973-
)
1982+
retriever: Union[
1983+
AsyncRetriever, CustomRetriever, SimpleRetriever, StateDelegatingRetriever
1984+
] = Field(
1985+
...,
1986+
description="Component used to coordinate how records are extracted across stream slices and request pages.",
1987+
title="Retriever",
19741988
)
19751989
incremental_sync: Optional[
19761990
Union[CustomIncrementalSync, DatetimeBasedCursor, IncrementingCountCursor]
@@ -1979,7 +1993,9 @@ class Config:
19791993
description="Component used to fetch data incrementally based on a time field in the data.",
19801994
title="Incremental Sync",
19811995
)
1982-
name: Optional[str] = Field("", description="The stream name.", example=["Users"], title="Name")
1996+
name: Optional[str] = Field(
1997+
"", description="The stream name.", example=["Users"], title="Name"
1998+
)
19831999
primary_key: Optional[PrimaryKey] = Field(
19842000
"", description="The primary key of the stream.", title="Primary Key"
19852001
)
@@ -2203,7 +2219,7 @@ class ParentStreamConfig(BaseModel):
22032219
examples=["id", "{{ config['parent_record_id'] }}"],
22042220
title="Parent Key",
22052221
)
2206-
stream: DeclarativeStream = Field(
2222+
stream: Union[DeclarativeStream, StateDelegatingStream] = Field(
22072223
..., description="Reference to the parent stream.", title="Parent Stream"
22082224
)
22092225
partition_field: str = Field(
@@ -2230,22 +2246,14 @@ class ParentStreamConfig(BaseModel):
22302246
parameters: Optional[Dict[str, Any]] = Field(None, alias="$parameters")
22312247

22322248

2233-
class StateDelegatingRetriever(BaseModel):
2234-
type: Literal["StateDelegatingRetriever"]
2235-
full_refresh_no_slice_in_params: Optional[bool] = Field(
2236-
False,
2237-
description="If set to true, a single slice will be used and its request options will be ignored when sending requests.",
2238-
)
2239-
full_refresh_ignore_min_max_datetime: Optional[bool] = Field(
2240-
False,
2241-
description="If set to true, a min and max limitation for start and end datetime will be ignored for full refresh retriever.",
2242-
)
2243-
full_refresh_retriever: Union[AsyncRetriever, CustomRetriever, SimpleRetriever] = Field(
2249+
class StateDelegatingStream(BaseModel):
2250+
type: Literal["StateDelegatingStream"]
2251+
full_refresh_stream: DeclarativeStream = Field(
22442252
...,
22452253
description="Component used to coordinate how records are extracted across stream slices and request pages when the state is empty or not provided.",
22462254
title="Retriever",
22472255
)
2248-
incremental_retriever: Union[AsyncRetriever, CustomRetriever, SimpleRetriever] = Field(
2256+
incremental_stream: DeclarativeStream = Field(
22492257
...,
22502258
description="Component used to coordinate how records are extracted across stream slices and request pages when the state provided.",
22512259
title="Retriever",
@@ -2276,7 +2284,11 @@ class SimpleRetriever(BaseModel):
22762284
CustomPartitionRouter,
22772285
ListPartitionRouter,
22782286
SubstreamPartitionRouter,
2279-
List[Union[CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter]],
2287+
List[
2288+
Union[
2289+
CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter
2290+
]
2291+
],
22802292
]
22812293
] = Field(
22822294
[],
@@ -2320,7 +2332,9 @@ class AsyncRetriever(BaseModel):
23202332
)
23212333
download_extractor: Optional[
23222334
Union[CustomRecordExtractor, DpathExtractor, ResponseToFileExtractor]
2323-
] = Field(None, description="Responsible for fetching the records from provided urls.")
2335+
] = Field(
2336+
None, description="Responsible for fetching the records from provided urls."
2337+
)
23242338
creation_requester: Union[CustomRequester, HttpRequester] = Field(
23252339
...,
23262340
description="Requester component that describes how to prepare HTTP requests to send to the source API to create the async server-side job.",
@@ -2354,7 +2368,11 @@ class AsyncRetriever(BaseModel):
23542368
CustomPartitionRouter,
23552369
ListPartitionRouter,
23562370
SubstreamPartitionRouter,
2357-
List[Union[CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter]],
2371+
List[
2372+
Union[
2373+
CustomPartitionRouter, ListPartitionRouter, SubstreamPartitionRouter
2374+
]
2375+
],
23582376
]
23592377
] = Field(
23602378
[],
@@ -2422,10 +2440,12 @@ class DynamicDeclarativeStream(BaseModel):
24222440
stream_template: DeclarativeStream = Field(
24232441
..., description="Reference to the stream template.", title="Stream Template"
24242442
)
2425-
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = Field(
2426-
...,
2427-
description="Component resolve and populates stream templates with components values.",
2428-
title="Components Resolver",
2443+
components_resolver: Union[HttpComponentsResolver, ConfigComponentsResolver] = (
2444+
Field(
2445+
...,
2446+
description="Component resolve and populates stream templates with components values.",
2447+
title="Components Resolver",
2448+
)
24292449
)
24302450

24312451

@@ -2438,6 +2458,6 @@ class DynamicDeclarativeStream(BaseModel):
24382458
DeclarativeStream.update_forward_refs()
24392459
SessionTokenAuthenticator.update_forward_refs()
24402460
DynamicSchemaLoader.update_forward_refs()
2441-
StateDelegatingRetriever.update_forward_refs()
2461+
ParentStreamConfig.update_forward_refs()
24422462
SimpleRetriever.update_forward_refs()
24432463
AsyncRetriever.update_forward_refs()

0 commit comments

Comments
 (0)