-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add a short guide on defining a configuration schema (#2449)
- Loading branch information
1 parent
9dfef92
commit 9e6da9d
Showing
3 changed files
with
39 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Defining a configuration schema | ||
|
||
The Singer SDK provides a way to define a configuration schema for your tap or target. This schema is used to validate the configuration provided by the user and to provide a default configuration when the user does not provide one. | ||
|
||
The configuration schema is defined as a JSON object that describes the configuration options that your tap or target supports. We recommend using the [JSON Schema helpers](../typing.rst) provided by the SDK to define the schema. | ||
|
||
Here is an example of a configuration schema for a tap: | ||
|
||
```python | ||
from singer_sdk import Tap | ||
from singer_sdk import typing as th | ||
|
||
|
||
class MyTap(Tap): | ||
name = "my-tap" | ||
|
||
config_jsonschema = th.PropertiesList( | ||
th.Property("api_key", th.StringType, required=True), | ||
th.Property("base_url", th.StringType, default="https://api.example.com"), | ||
th.Property("start_date", th.DateTimeType), | ||
).to_dict() | ||
``` | ||
|
||
Explanation of the configuration schema defined above: | ||
|
||
- The `config_jsonschema` attribute is a JSON object that describes the configuration options that the tap supports. | ||
- The `th.PropertiesList` helper is used to define a list of properties. | ||
- The `th.Property` helper is used to define a property with a name, type, and other attributes. | ||
- The `th.StringType`, `th.DateTimeType`, etc. helpers are used to define the type of the property. | ||
- The `required` attribute is used to mark a property as required. The tap will throw an error if the user does not provide a value for a required property. | ||
- The `default` attribute is used to provide a default value for a property. The tap will use this if the user does not provide a value, so this can be accessed in the tap or streams with square bracket syntax, i.e. `self.config["base_url"]`. | ||
- The `to_dict()` method is used to convert the JSON object to a Python dictionary. | ||
|
||
See the full reference for the [typing module](../typing.rst) for more information on how to define a configuration schema. |
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