-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[low-code connectors]: Assert there are no custom top-level fields (#…
…15489) * move components to definitions field * Also update the references * validate the top level fields and add version * raise exception on unknown fields * newline * unit tests * set version to 0.1.0 * newline
- Loading branch information
Showing
6 changed files
with
104 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
airbyte-cdk/python/unit_tests/sources/declarative/test_yaml_declarative_source.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# | ||
# Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
import os | ||
import tempfile | ||
import unittest | ||
|
||
from airbyte_cdk.sources.declarative.exceptions import InvalidConnectorDefinitionException | ||
from airbyte_cdk.sources.declarative.yaml_declarative_source import YamlDeclarativeSource | ||
|
||
|
||
class TestYamlDeclarativeSource(unittest.TestCase): | ||
def test_source_is_created_if_toplevel_fields_are_known(self): | ||
content = """ | ||
version: "version" | ||
streams: "streams" | ||
check: "check" | ||
""" | ||
temporary_file = TestFileContent(content) | ||
YamlDeclarativeSource(temporary_file.filename) | ||
|
||
def test_source_is_not_created_if_toplevel_fields_are_unknown(self): | ||
content = """ | ||
version: "version" | ||
streams: "streams" | ||
check: "check" | ||
not_a_valid_field: "error" | ||
""" | ||
temporary_file = TestFileContent(content) | ||
with self.assertRaises(InvalidConnectorDefinitionException): | ||
YamlDeclarativeSource(temporary_file.filename) | ||
|
||
|
||
class TestFileContent: | ||
def __init__(self, content): | ||
self.file = tempfile.NamedTemporaryFile(mode="w", delete=False) | ||
|
||
with self.file as f: | ||
f.write(content) | ||
|
||
@property | ||
def filename(self): | ||
return self.file.name | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, type, value, traceback): | ||
os.unlink(self.filename) |
74 changes: 38 additions & 36 deletions
74
...emplates/source-configuration-based/source_{{snakeCase name}}/{{snakeCase name}}.yaml.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,44 @@ | ||
schema_loader: | ||
type: JsonSchema | ||
file_path: "./source_{{snakeCase name}}/schemas/\{{ options['name'] }}.json" | ||
selector: | ||
type: RecordSelector | ||
extractor: | ||
type: JelloExtractor | ||
transform: "_" | ||
requester: | ||
type: HttpRequester | ||
name: "\{{ options['name'] }}" | ||
http_method: "GET" | ||
authenticator: | ||
type: BearerAuthenticator | ||
api_token: "\{{ config['api_key'] }}" | ||
retriever: | ||
type: SimpleRetriever | ||
$options: | ||
url_base: TODO "your_api_base_url" | ||
name: "\{{ options['name'] }}" | ||
primary_key: "\{{ options['primary_key'] }}" | ||
record_selector: | ||
$ref: "*ref(selector)" | ||
paginator: | ||
type: NoPagination | ||
customers_stream: | ||
type: DeclarativeStream | ||
$options: | ||
name: "customers" | ||
primary_key: "id" | ||
version: "0.1.0" | ||
|
||
definitions: | ||
schema_loader: | ||
$ref: "*ref(schema_loader)" | ||
type: JsonSchema | ||
file_path: "./source_{{snakeCase name}}/schemas/\{{ options['name'] }}.json" | ||
selector: | ||
type: RecordSelector | ||
extractor: | ||
type: JelloExtractor | ||
transform: "_" | ||
requester: | ||
type: HttpRequester | ||
name: "\{{ options['name'] }}" | ||
http_method: "GET" | ||
authenticator: | ||
type: BearerAuthenticator | ||
api_token: "\{{ config['api_key'] }}" | ||
retriever: | ||
$ref: "*ref(retriever)" | ||
requester: | ||
$ref: "*ref(requester)" | ||
path: TODO "your_endpoint_path" | ||
type: SimpleRetriever | ||
$options: | ||
url_base: TODO "your_api_base_url" | ||
name: "\{{ options['name'] }}" | ||
primary_key: "\{{ options['primary_key'] }}" | ||
record_selector: | ||
$ref: "*ref(definitions.selector)" | ||
paginator: | ||
type: NoPagination | ||
|
||
streams: | ||
- "*ref(customers_stream)" | ||
- type: DeclarativeStream | ||
$options: | ||
name: "customers" | ||
primary_key: "id" | ||
schema_loader: | ||
$ref: "*ref(definitions.schema_loader)" | ||
retriever: | ||
$ref: "*ref(definitions.retriever)" | ||
requester: | ||
$ref: "*ref(definitions.requester)" | ||
path: TODO "your_endpoint_path" | ||
check: | ||
type: CheckStream | ||
stream_names: ["customers"] |