Skip to content

Commit

Permalink
Allow for custom requesters to be defined in low-code manifests (#21001)
Browse files Browse the repository at this point in the history
* Allow for custom requesters to be defined in low-code manifests

* add test for custom requester component

* bump versions and changelog
  • Loading branch information
brianjlai authored and jbfbell committed Jan 13, 2023
1 parent 972794a commit c779c49
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 4 deletions.
3 changes: 3 additions & 0 deletions airbyte-cdk/python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.18.1
Allow for CustomRequester to be defined within declarative manifests

## 0.18.0
Adding `cursor_granularity` to the declarative API of DatetimeStreamSlicer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,23 @@ definitions:
$options:
type: object
additionalProperties: true
CustomRequester:
description: Requester component whose behavior is derived from a custom code implementation of the connector
type: object
additionalProperties: true
required:
- type
- class_name
properties:
type:
type: string
enum: [CustomRequester]
class_name:
type: string
additionalProperties: true
$options:
type: object
additionalProperties: true
CustomRetriever:
description: Retriever component whose behavior is derived from a custom code implementation of the connector
type: object
Expand Down Expand Up @@ -963,7 +980,9 @@ definitions:
record_selector:
"$ref": "#/definitions/RecordSelector"
requester:
"$ref": "#/definitions/HttpRequester"
anyOf:
- "$ref": "#/definitions/CustomRequester"
- "$ref": "#/definitions/HttpRequester"
name:
type: string
default: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ class Config:
_options: Optional[Dict[str, Any]] = Field(None, alias="$options")


class CustomRequester(BaseModel):
class Config:
extra = Extra.allow

type: Literal["CustomRequester"]
class_name: str
_options: Optional[Dict[str, Any]] = Field(None, alias="$options")


class CustomRetriever(BaseModel):
class Config:
extra = Extra.allow
Expand Down Expand Up @@ -461,7 +470,7 @@ class ParentStreamConfig(BaseModel):
class SimpleRetriever(BaseModel):
type: Literal["SimpleRetriever"]
record_selector: RecordSelector
requester: HttpRequester
requester: Union[CustomRequester, HttpRequester]
name: Optional[str] = ""
paginator: Optional[Union[DefaultPaginator, NoPagination]] = None
primary_key: Optional[PrimaryKey] = None
Expand Down
2 changes: 1 addition & 1 deletion airbyte-cdk/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name="airbyte-cdk",
version="0.18.0",
version="0.18.1",
description="A framework for writing Airbyte Connectors.",
long_description=README,
long_description_content_type="text/markdown",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#

from airbyte_cdk.sources.declarative.requesters import HttpRequester


class SampleCustomComponent(HttpRequester):
"""
A test class used to validate manifests that rely on custom defined Python components
"""

pass
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,31 @@ def test_valid_manifest(self):
},
"record_selector": {"extractor": {"field_pointer": ["result"]}},
},
}
},
{
"type": "DeclarativeStream",
"$options": {"name": "stream_with_custom_requester", "primary_key": "id", "url_base": "https://api.sendgrid.com"},
"schema_loader": {
"name": "{{ options.stream_name }}",
"file_path": "./source_sendgrid/schemas/{{ options.name }}.yaml",
},
"retriever": {
"paginator": {
"type": "DefaultPaginator",
"page_size": 10,
"page_size_option": {"inject_into": "request_parameter", "field_name": "page_size"},
"page_token_option": {"inject_into": "path"},
"pagination_strategy": {"type": "CursorPagination", "cursor_value": "{{ response._metadata.next }}"},
},
"requester": {
"type": "CustomRequester",
"class_name": "unit_tests.sources.declarative.external_component.SampleCustomComponent",
"path": "/v3/marketing/lists",
"custom_request_parameters": {"page_size": 10},
},
"record_selector": {"extractor": {"field_pointer": ["result"]}},
},
},
],
"check": {"type": "CheckStream", "stream_names": ["lists"]},
}
Expand Down

0 comments on commit c779c49

Please sign in to comment.