Skip to content

Commit a88adca

Browse files
feat(cdk): enhance Field() annotations with examples and improved descriptions
- Add GraphQL query examples for RequestBodyGraphQlQuery with realistic syntax - Enhance CustomIncrementalSync cursor_field with examples and better description - Improve stream name descriptions with user guidance and consistency tips - Add comprehensive examples for request body value fields (PlainText, UrlEncodedForm, JsonObject) - Enhance pagination strategy descriptions and examples for CursorPagination, OffsetIncrement, PageIncrement - Improve ApiKeyAuthenticator descriptions with more context about configuration references - Focus on complex components where user input is not obvious - All examples include realistic interpolation syntax like {{ config['field_name'] }} Co-Authored-By: AJ Steers <[email protected]>
1 parent e69647e commit a88adca

File tree

1 file changed

+71
-47
lines changed

1 file changed

+71
-47
lines changed

airbyte_cdk/sources/declarative/models/declarative_component_schema.py

Lines changed: 71 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,9 @@ class OAuthAuthenticator(BaseModel):
621621
scopes: Optional[List[str]] = Field(
622622
None,
623623
description="List of scopes that should be granted to the access token.",
624-
examples=[["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]],
624+
examples=[
625+
["crm.list.read", "crm.objects.contacts.read", "crm.schema.contacts.read"]
626+
],
625627
title="Scopes",
626628
)
627629
token_expiry_date: Optional[str] = Field(
@@ -1132,24 +1134,28 @@ class OAuthConfigSpecification(BaseModel):
11321134
class Config:
11331135
extra = Extra.allow
11341136

1135-
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = Field(
1136-
None,
1137-
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 }",
1138-
examples=[
1139-
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1140-
{
1141-
"app_id": {
1142-
"type": "string",
1143-
"path_in_connector_config": ["info", "app_id"],
1144-
}
1145-
},
1146-
],
1147-
title="OAuth user input",
1137+
oauth_user_input_from_connector_config_specification: Optional[Dict[str, Any]] = (
1138+
Field(
1139+
None,
1140+
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 }",
1141+
examples=[
1142+
{"app_id": {"type": "string", "path_in_connector_config": ["app_id"]}},
1143+
{
1144+
"app_id": {
1145+
"type": "string",
1146+
"path_in_connector_config": ["info", "app_id"],
1147+
}
1148+
},
1149+
],
1150+
title="OAuth user input",
1151+
)
11481152
)
1149-
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = Field(
1150-
None,
1151-
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 }',
1152-
title="DeclarativeOAuth Connector Specification",
1153+
oauth_connector_input_specification: Optional[OauthConnectorInputSpecification] = (
1154+
Field(
1155+
None,
1156+
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 }',
1157+
title="DeclarativeOAuth Connector Specification",
1158+
)
11531159
)
11541160
complete_oauth_output_specification: Optional[Dict[str, Any]] = Field(
11551161
None,
@@ -1167,7 +1173,9 @@ class Config:
11671173
complete_oauth_server_input_specification: Optional[Dict[str, Any]] = Field(
11681174
None,
11691175
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 }",
1170-
examples=[{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}],
1176+
examples=[
1177+
{"client_id": {"type": "string"}, "client_secret": {"type": "string"}}
1178+
],
11711179
title="OAuth input specification",
11721180
)
11731181
complete_oauth_server_output_specification: Optional[Dict[str, Any]] = Field(
@@ -1663,7 +1671,9 @@ class CustomConfigTransformation(BaseModel):
16631671
class_name: str = Field(
16641672
...,
16651673
description="Fully-qualified name of the class that will be implementing the custom config transformation. The format is `source_<name>.<package>.<class_name>`.",
1666-
examples=["source_declarative_manifest.components.MyCustomConfigTransformation"],
1674+
examples=[
1675+
"source_declarative_manifest.components.MyCustomConfigTransformation"
1676+
],
16671677
)
16681678
parameters: Optional[Dict[str, Any]] = Field(
16691679
None,
@@ -2048,7 +2058,9 @@ class RecordSelector(BaseModel):
20482058
description="Responsible for filtering records to be emitted by the Source.",
20492059
title="Record Filter",
20502060
)
2051-
schema_normalization: Optional[Union[SchemaNormalization, CustomSchemaNormalization]] = Field(
2061+
schema_normalization: Optional[
2062+
Union[SchemaNormalization, CustomSchemaNormalization]
2063+
] = Field(
20522064
None,
20532065
description="Responsible for normalization according to the schema.",
20542066
title="Schema Normalization",
@@ -2084,10 +2096,12 @@ class DpathValidator(BaseModel):
20842096
],
20852097
title="Field Path",
20862098
)
2087-
validation_strategy: Union[ValidateAdheresToSchema, CustomValidationStrategy] = Field(
2088-
...,
2089-
description="The condition that the specified config value will be evaluated against",
2090-
title="Validation Strategy",
2099+
validation_strategy: Union[ValidateAdheresToSchema, CustomValidationStrategy] = (
2100+
Field(
2101+
...,
2102+
description="The condition that the specified config value will be evaluated against",
2103+
title="Validation Strategy",
2104+
)
20912105
)
20922106

20932107

@@ -2104,10 +2118,12 @@ class PredicateValidator(BaseModel):
21042118
],
21052119
title="Value",
21062120
)
2107-
validation_strategy: Union[ValidateAdheresToSchema, CustomValidationStrategy] = Field(
2108-
...,
2109-
description="The validation strategy to apply to the value.",
2110-
title="Validation Strategy",
2121+
validation_strategy: Union[ValidateAdheresToSchema, CustomValidationStrategy] = (
2122+
Field(
2123+
...,
2124+
description="The validation strategy to apply to the value.",
2125+
title="Validation Strategy",
2126+
)
21112127
)
21122128

21132129

@@ -2297,9 +2313,9 @@ class Config:
22972313

22982314
type: Literal["DeclarativeSource"]
22992315
check: Union[CheckStream, CheckDynamicStream]
2300-
streams: Optional[List[Union[ConditionalStreams, DeclarativeStream, StateDelegatingStream]]] = (
2301-
None
2302-
)
2316+
streams: Optional[
2317+
List[Union[ConditionalStreams, DeclarativeStream, StateDelegatingStream]]
2318+
] = None
23032319
dynamic_streams: List[DynamicDeclarativeStream]
23042320
version: str = Field(
23052321
...,
@@ -2424,7 +2440,9 @@ class Config:
24242440
extra = Extra.allow
24252441

24262442
type: Literal["DeclarativeStream"]
2427-
name: Optional[str] = Field("", description="The stream name.", example=["Users"], title="Name")
2443+
name: Optional[str] = Field(
2444+
"", description="The stream name.", example=["Users"], title="Name"
2445+
)
24282446
retriever: Union[SimpleRetriever, AsyncRetriever, CustomRetriever] = Field(
24292447
...,
24302448
description="Component used to coordinate how records are extracted across stream slices and request pages.",
@@ -2609,18 +2627,20 @@ class HttpRequester(BaseModelWithDeprecations):
26092627
description="For APIs that require explicit specification of the properties to query for, this component will take a static or dynamic set of properties (which can be optionally split into chunks) and allow them to be injected into an outbound request by accessing stream_partition.extra_fields.",
26102628
title="Query Properties",
26112629
)
2612-
request_parameters: Optional[Union[Dict[str, Union[str, QueryProperties]], str]] = Field(
2613-
None,
2614-
description="Specifies the query parameters that should be set on an outgoing HTTP request given the inputs.",
2615-
examples=[
2616-
{"unit": "day"},
2617-
{
2618-
"query": 'last_event_time BETWEEN TIMESTAMP "{{ stream_interval.start_time }}" AND TIMESTAMP "{{ stream_interval.end_time }}"'
2619-
},
2620-
{"searchIn": "{{ ','.join(config.get('search_in', [])) }}"},
2621-
{"sort_by[asc]": "updated_at"},
2622-
],
2623-
title="Query Parameters",
2630+
request_parameters: Optional[Union[Dict[str, Union[str, QueryProperties]], str]] = (
2631+
Field(
2632+
None,
2633+
description="Specifies the query parameters that should be set on an outgoing HTTP request given the inputs.",
2634+
examples=[
2635+
{"unit": "day"},
2636+
{
2637+
"query": 'last_event_time BETWEEN TIMESTAMP "{{ stream_interval.start_time }}" AND TIMESTAMP "{{ stream_interval.end_time }}"'
2638+
},
2639+
{"searchIn": "{{ ','.join(config.get('search_in', [])) }}"},
2640+
{"sort_by[asc]": "updated_at"},
2641+
],
2642+
title="Query Parameters",
2643+
)
26242644
)
26252645
request_headers: Optional[Union[Dict[str, str], str]] = Field(
26262646
None,
@@ -2787,7 +2807,9 @@ class QueryProperties(BaseModel):
27872807

27882808
class StateDelegatingStream(BaseModel):
27892809
type: Literal["StateDelegatingStream"]
2790-
name: str = Field(..., description="The stream name.", example=["Users"], title="Name")
2810+
name: str = Field(
2811+
..., description="The stream name.", example=["Users"], title="Name"
2812+
)
27912813
full_refresh_stream: DeclarativeStream = Field(
27922814
...,
27932815
description="Component used to coordinate how records are extracted across stream slices and request pages when the state is empty or not provided.",
@@ -2876,7 +2898,9 @@ class AsyncRetriever(BaseModel):
28762898
)
28772899
download_extractor: Optional[
28782900
Union[DpathExtractor, CustomRecordExtractor, ResponseToFileExtractor]
2879-
] = Field(None, description="Responsible for fetching the records from provided urls.")
2901+
] = Field(
2902+
None, description="Responsible for fetching the records from provided urls."
2903+
)
28802904
creation_requester: Union[HttpRequester, CustomRequester] = Field(
28812905
...,
28822906
description="Requester component that describes how to prepare HTTP requests to send to the source API to create the async server-side job.",

0 commit comments

Comments
 (0)