Skip to content

Commit 939e9f3

Browse files
author
Oleksandr Bazarnov
committed
adjust the schema and routing logic
1 parent a1dd40b commit 939e9f3

File tree

4 files changed

+228
-52
lines changed

4 files changed

+228
-52
lines changed

airbyte_cdk/sources/declarative/declarative_component_schema.yaml

Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,7 +2048,10 @@ definitions:
20482048
title: Request Body Payload to be send as a part of the API request.
20492049
description: Specifies how to populate the body of the request with a payload. Can contain nested objects.
20502050
anyOf:
2051-
- "$ref": "#/definitions/RequestBody"
2051+
- "$ref": "#/definitions/RequestBodyPlainText"
2052+
- "$ref": "#/definitions/RequestBodyUrlEncodedForm"
2053+
- "$ref": "#/definitions/RequestBodyJsonObject"
2054+
- "$ref": "#/definitions/RequestBodyGraphQL"
20522055
interpolation_context:
20532056
- next_page_token
20542057
- stream_interval
@@ -4073,27 +4076,74 @@ definitions:
40734076
- type
40744077
- stream_template
40754078
- components_resolver
4076-
RequestBody:
4079+
RequestBodyPlainText:
4080+
title: Plain-text Body
4081+
description: Request body value is sent as plain text
40774082
type: object
4078-
description: The request body payload. Can be either URL encoded data or JSON.
4083+
required:
4084+
- type
4085+
- value
40794086
properties:
40804087
type:
4081-
anyOf:
4082-
- type: string
4083-
enum: [RequestBodyData]
4084-
- type: string
4085-
enum: [RequestBodyJson]
4088+
type: string
4089+
enum: [RequestBodyPlainText]
40864090
value:
4087-
anyOf:
4088-
- type: string
4089-
description: The request body payload as a string.
4090-
- type: object
4091-
description: The request body payload as a Non-JSON object (url-encoded data).
4092-
additionalProperties:
4093-
type: string
4094-
- type: object
4095-
description: The request body payload as a JSON object (json-encoded data).
4096-
additionalProperties: true
4091+
type: string
4092+
RequestBodyUrlEncodedForm:
4093+
title: URL-encoded Body
4094+
description: Request body value is converted into a url-encoded form
4095+
type: object
4096+
required:
4097+
- type
4098+
- value
4099+
properties:
4100+
type:
4101+
type: string
4102+
enum: [RequestBodyUrlEncodedForm]
4103+
value:
4104+
type: object
4105+
additionalProperties:
4106+
type: string
4107+
RequestBodyJsonObject:
4108+
title: Json Object Body
4109+
description: Request body value is converted into a url-encoded form
4110+
type: object
4111+
required:
4112+
- type
4113+
- value
4114+
properties:
4115+
type:
4116+
type: string
4117+
enum: [RequestBodyJsonObject]
4118+
value:
4119+
type: object
4120+
additionalProperties: true
4121+
RequestBodyGraphQL:
4122+
title: GraphQL Body
4123+
description: Request body is a GraphQL query object
4124+
type: object
4125+
required:
4126+
- type
4127+
- value
4128+
properties:
4129+
type:
4130+
type: string
4131+
enum: [RequestBodyGraphQL]
4132+
value:
4133+
"$ref": "#/definitions/RequestBodyGraphQlQuery"
4134+
RequestBodyGraphQlQuery:
4135+
title: GraphQL Query Body
4136+
description: Request body GraphQL query object
4137+
type: object
4138+
required:
4139+
- query
4140+
properties:
4141+
query:
4142+
type: object
4143+
additionalProperties: true
4144+
description: The GraphQL query to be executed
4145+
default: {}
4146+
additionalProperties: true
40974147
interpolation:
40984148
variables:
40994149
- title: config

airbyte_cdk/sources/declarative/models/declarative_component_schema.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
2-
31
# generated by datamodel-codegen:
42
# filename: declarative_component_schema.yaml
53

@@ -1501,9 +1499,26 @@ class ConfigComponentsResolver(BaseModel):
15011499
parameters: Optional[Dict[str, Any]] = Field(None, alias="$parameters")
15021500

15031501

1504-
class RequestBody(BaseModel):
1505-
type: Optional[Union[Literal["RequestBodyData"], Literal["RequestBodyJson"]]] = None
1506-
value: Optional[Union[str, Dict[str, str], Dict[str, Any]]] = None
1502+
class RequestBodyPlainText(BaseModel):
1503+
type: Literal["RequestBodyPlainText"]
1504+
value: str
1505+
1506+
1507+
class RequestBodyUrlEncodedForm(BaseModel):
1508+
type: Literal["RequestBodyUrlEncodedForm"]
1509+
value: Dict[str, str]
1510+
1511+
1512+
class RequestBodyJsonObject(BaseModel):
1513+
type: Literal["RequestBodyJsonObject"]
1514+
value: Dict[str, Any]
1515+
1516+
1517+
class RequestBodyGraphQlQuery(BaseModel):
1518+
class Config:
1519+
extra = Extra.allow
1520+
1521+
query: Dict[str, Any] = Field(..., description="The GraphQL query to be executed")
15071522

15081523

15091524
class AddedFieldDefinition(BaseModel):
@@ -1908,6 +1923,11 @@ class Spec(BaseModel):
19081923
)
19091924

19101925

1926+
class RequestBodyGraphQL(BaseModel):
1927+
type: Literal["RequestBodyGraphQL"]
1928+
value: RequestBodyGraphQlQuery
1929+
1930+
19111931
class CompositeErrorHandler(BaseModel):
19121932
type: Literal["CompositeErrorHandler"]
19131933
error_handlers: List[Union[CompositeErrorHandler, DefaultErrorHandler]] = Field(
@@ -2305,7 +2325,14 @@ class HttpRequester(BaseModelWithDeprecations):
23052325
],
23062326
title="Request Body JSON Payload",
23072327
)
2308-
request_body: Optional[RequestBody] = Field(
2328+
request_body: Optional[
2329+
Union[
2330+
RequestBodyPlainText,
2331+
RequestBodyUrlEncodedForm,
2332+
RequestBodyJsonObject,
2333+
RequestBodyGraphQL,
2334+
]
2335+
] = Field(
23092336
None,
23102337
description="Specifies how to populate the body of the request with a payload. Can contain nested objects.",
23112338
examples=[

airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_options_provider.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
from airbyte_cdk.sources.declarative.interpolation.interpolated_nested_mapping import NestedMapping
99
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
10-
RequestBody,
10+
RequestBodyGraphQL,
11+
RequestBodyJsonObject,
12+
RequestBodyPlainText,
13+
RequestBodyUrlEncodedForm,
1114
)
1215
from airbyte_cdk.sources.declarative.requesters.request_options.interpolated_nested_request_input_provider import (
1316
InterpolatedNestedRequestInputProvider,
@@ -41,7 +44,14 @@ class InterpolatedRequestOptionsProvider(RequestOptionsProvider):
4144
config: Config = field(default_factory=dict)
4245
request_parameters: Optional[RequestInput] = None
4346
request_headers: Optional[RequestInput] = None
44-
request_body: Optional[RequestBody] = None
47+
request_body: Optional[
48+
Union[
49+
RequestBodyGraphQL,
50+
RequestBodyJsonObject,
51+
RequestBodyPlainText,
52+
RequestBodyUrlEncodedForm,
53+
]
54+
] = None
4555
request_body_data: Optional[RequestInput] = None
4656
request_body_json: Optional[NestedMapping] = None
4757
query_properties_key: Optional[str] = None
@@ -83,14 +93,18 @@ def _resolve_request_body(self) -> None:
8393
based on the type specified in `self.request_body`. If neither is provided, both are initialized as empty
8494
dictionaries. Raises a ValueError if both `request_body_data` and `request_body_json` are set simultaneously.
8595
Raises:
86-
ValueError: If both `request_body_data` and `request_body_json` are provided.
96+
ValueError: if an unsupported request body type is provided.
8797
"""
8898
# Resolve the request body to either data or json
8999
if self.request_body is not None and self.request_body.type is not None:
90-
if self.request_body.type == "RequestBodyData":
100+
if self.request_body.type == "RequestBodyUrlEncodedForm":
91101
self.request_body_data = self.request_body.value
92-
elif self.request_body.type == "RequestBodyJson":
102+
elif self.request_body.type == "RequestBodyGraphQL":
103+
self.request_body_json = {"query": self.request_body.value.query}
104+
elif self.request_body.type in ("RequestBodyJsonObject", "RequestBodyPlainText"):
93105
self.request_body_json = self.request_body.value
106+
else:
107+
raise ValueError(f"Unsupported request body type: {self.request_body.type}")
94108

95109
def get_request_params(
96110
self,

0 commit comments

Comments
 (0)