Skip to content

Commit

Permalink
Use JSON schema title for setting labels
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Sep 19, 2024
1 parent 8e3a87e commit 5738084
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 15 deletions.
3 changes: 2 additions & 1 deletion hub_utils/meltano_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,15 @@ def _parse_sdk_about_settings(sdk_about_dict, enforce_desc=False):
base_required = settings_raw.get("required", [])
for settings in MeltanoUtil._traverse_schema_properties(settings_raw):
name = settings.get("name")
title = settings.get("title")
description = MeltanoUtil._handle_description(
MeltanoUtil._clean_description(settings.get("description")),
name,
enforce_desc,
)
setting_details = {
"name": name,
"label": MeltanoUtil._get_label(name),
"label": title or MeltanoUtil._get_label(name),
"description": description,
}
kind = MeltanoUtil._get_kind_from_type(
Expand Down
33 changes: 33 additions & 0 deletions tests/data/tap_with_rich_config_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "tap-example",
"description": "Singer.io tap for extracting data from example",
"version": "0.1.0",
"sdk_version": "0.40.0",
"capabilities": [
"catalog",
"state",
"discover",
"about",
"stream-maps",
"schema-flattening"
],
"settings": {
"type": "object",
"properties": {
"username": {
"type": "string",
"description": "The username to use when authenticating with the API"
},
"password": {
"type": "string",
"description": "The password to use when authenticating with the API"
},
"cmo": {
"type": ["string", "null"],
"title": "Client Management Organization",
"description": "The client management organization to use when authenticating with the API"
}
},
"required": ["username", "password"]
}
}
56 changes: 42 additions & 14 deletions tests/test_meltano_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,34 @@ def test_sdk_about_parsing_2():
]


def test_sdk_about_parsing_3():
sdk_about_dict = _read_data('tap_with_rich_config_schema.json')

settings, _, _ = MeltanoUtil._parse_sdk_about_settings(sdk_about_dict)

assert settings == [
{
"name": "username",
"label": "Username",
"description": "The username to use when authenticating with the API",
"kind": "string"
},
{
"name": "password",
"label": "Password",
"description": "The password to use when authenticating with the API",
"kind": "password",
"sensitive": True,
},
{
"name": "cmo",
"label": "Client Management Organization",
"description": "The client management organization to use when authenticating with the API",
"kind": "string"
},
]


def test_sdk_about_parsing_airbyte():
sdk_about_dict = _read_data('airbyte_s3_about.json')

Expand All @@ -145,83 +173,83 @@ def test_sdk_about_parsing_airbyte():
},
{
"name": "connector_config.dataset",
"label": "Connector Config Dataset",
"label": "Output Stream Name",
"description": "The name of the stream you would like this source to output. Can contain letters, numbers, or underscores.",
"kind": "string"
},
{
"name": "connector_config.path_pattern",
"label": "Connector Config Path Pattern",
"label": "Pattern of files to replicate",
"description": "A regular expression which tells the connector which files to replicate. All files which match this pattern will be replicated. Use | to separate multiple patterns. See <a href=\"https://facelessuser.github.io/wcmatch/glob/\" target=\"_blank\">this page</a> to understand pattern syntax (GLOBSTAR and SPLIT flags are enabled). Use pattern <strong>**</strong> to pick up all files.",
"kind": "string"
},
# Format
{
"name": "connector_config.format.filetype",
"label": "Connector Config Format Filetype",
"label": "Filetype",
"description": "Csv, Parquet",
"kind": "string"
},
{
"name": "connector_config.format.delimiter",
"label": "Connector Config Format Delimiter",
"label": "Delimiter",
"description": "The character delimiting individual cells in the CSV data. This may only be a 1-character string. For tab-delimited data enter '\\t'.",
"kind": "string",
"value": ","
},
{
"name": "connector_config.format.columns",
"label": "Connector Config Format Columns",
"label": "Selected Columns",
"description": "If you only want to sync a subset of the columns from the file(s), add the columns you want here as a comma-delimited list. Leave it empty to sync all columns.",
"kind": "array"
},
{
"name": "connector_config.format.buffer_size",
"label": "Connector Config Format Buffer Size",
"label": "Buffer Size",
"description": "Perform read buffering when deserializing individual column chunks. By default every group column will be loaded fully to memory. This option can help avoid out-of-memory errors if your data is particularly wide.",
"kind": "integer",
"value": 2
},
# End after tweaks
{
"name": "connector_config.schema",
"label": "Connector Config Schema",
"label": "Manually enforced data schema",
"description": "Optionally provide a schema to enforce, as a valid JSON string. Ensure this is a mapping of <strong>{ \"column\" : \"type\" }</strong>, where types are valid <a href=\"https://json-schema.org/understanding-json-schema/reference/type.html\" target=\"_blank\">JSON Schema datatypes</a>. Leave as {} to auto-infer the schema.",
"kind": "string",
"value": "{}"
},
{
"name": "connector_config.provider.bucket",
"label": "Connector Config Provider Bucket",
"label": "Bucket",
"description": "Name of the S3 bucket where the file(s) exist.",
"kind": "password",
"sensitive": True,
},
{
"name": "connector_config.provider.aws_access_key_id",
"label": "Connector Config Provider AWS Access Key ID",
"label": "AWS Access Key ID",
"description": "In order to access private Buckets stored on AWS S3, this connector requires credentials with the proper permissions. If accessing publicly available data, this field is not necessary.",
"kind": "password",
"sensitive": True,
},
{
"name": "connector_config.provider.aws_secret_access_key",
"label": "Connector Config Provider AWS Secret Access Key",
"label": "AWS Secret Access Key",
"description": "In order to access private Buckets stored on AWS S3, this connector requires credentials with the proper permissions. If accessing publicly available data, this field is not necessary.",
"kind": "password",
"sensitive": True,
},
{
"name": "connector_config.provider.path_prefix",
"label": "Connector Config Provider Path Prefix",
"label": "Path Prefix",
"description": "By providing a path-like prefix (e.g. myFolder/thisTable/) under which all the relevant files sit, we can optimize finding these in S3. This is optional but recommended if your bucket contains many folders/files which you don't need to replicate.",
"kind": "password",
"sensitive": True,
"value": ""
},
{
"name": "connector_config.provider.endpoint",
"label": "Connector Config Provider Endpoint",
"label": "Endpoint",
"description": "Endpoint to an S3 compatible service. Leave empty to use AWS.",
"kind": "password",
"sensitive": True,
Expand Down Expand Up @@ -294,7 +322,7 @@ def test_airbyte_array_enum_array():
assert settings == [
{
"name": "connector_config.metrics",
"label": "Connector Config Metrics",
"label": "Metrics to ingest",
"description": "Select at least one metric to query.",
"kind": "array",
}
Expand All @@ -316,7 +344,7 @@ def test_airbyte_array_enum_string():
assert settings == [
{
"name": "connector_config.region",
"label": "Connector Config Region",
"label": "AWS Region",
"description": "AWS Region of the SQS Queue",
"kind": "options",
"options": [
Expand Down

0 comments on commit 5738084

Please sign in to comment.