Code patterns are a special type of component. Their behavior is specified in their interface.
The instructions below refer to the general component quick start, highlighting the steps specific to code patterns.
First, follow the common steps for creating a component:
Select Code Pattern
as the type.
Modify the settings described in Interface - Developer Portal.
Go on following the component quick start:
Learn how the whole code generation process works.
Implement the Generate action as specified in Interface - Generate Action:
action = generate
is expected.run
).stdout
.exit code = 0
if successful.Unlike other components, the code pattern component cannot be run, and will be invisible in the user interface until it is published.
However, there are two other ways to try it as a component, as described below.
The first option is to call the generate action via the API:
The second option is to modify the transformation to use an unpublished code pattern.
First, click Transformations on the project menu. Then click New Transformation to create a new transformation.
In the modal, click on the selected type of the transformation.
Fill in the name and, optionally, the description. Do not select any code pattern.
You have created an empty transformation.
Make note of the component and configuration ID from the URL. You will need them in the API calls.
/admin/projects/{PROJECT_ID}/transformations-v2/{COMPONENT_ID}/{CONFIGURATION_ID}
Set the code pattern to the transformation via Storage API.
Load the configuration in the JSON format via the Configuration Detail API call.
curl \
--include \
--header "X-StorageApi-Token: {API_TOKEN}" \
'{STORAGE API}/v2/storage/components/{COMPONENT_ID}/configs/{CONFIGURATION_ID}'
This is an example response, some keys are omitted.
{
"id": "1234",
"name": "API test",
"configuration": {}
}
It is necessary to set the ID of the code pattern component to the configuration.
{
"configuration": {
"runtime": {
"codePattern": {
"componentId": "keboola.example-pattern"
}
}
}
}
Update the configuration via the Update Configuration API call. JSON must be url-encoded.
curl
--include \
--request PUT \
--header "X-StorageApi-Token: {API_TOKEN}" \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-binary "configuration=%7B%22runtime%22%3A%7B%22codePattern%22%3A%7B%22componentId%22%3A%22keboola.example-pattern%22%7D%7D%7D" \
'{STORAGE API}/v2/storage/components/{COMPONENT_ID}/configs/{CONFIGURATION_ID}'
This is an example response, some keys are omitted.
{
"id": "1234",
"name": "API test",
"configuration": {
"runtime": {
"codePattern": {
"componentId": "keboola.example-pattern"
}
}
}
}
The transformation now uses the code pattern, and you can test it in the user interface.
Make sure the component is set up according to Interface - Developer Portal. Then follow the tutorial Publish Component.