Skip to content

Commit 996b0c4

Browse files
authored
Merge pull request serverlessworkflow#969 from neuroglia-io/fix-custom-function-documentation
Fix custom function documentation
2 parents be65792 + 726bcad commit 996b0c4

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

dsl.md

+38-29
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
+ [Interoperability](#interoperability)
2222
- [Supported Protocols](#supported-protocols)
2323
- [Custom and Non-Standard Interactions](#custom-and-non-standard-interactions)
24-
- [Creating a Custom Function](#creating-a-custom-function)
25-
- [Using a Custom Function](#using-a-custom-function)
26-
- [Publishing a Custom Function](#publishing-a-custom-function)
24+
+ [Creating a Custom Function](#creating-a-custom-function)
25+
+ [Using a Custom Function](#using-a-custom-function)
26+
+ [Publishing a Custom Function](#publishing-a-custom-function)
2727
+ [Events](#events)
2828
+ [Extensions](#extensions)
2929
+ [External Resources](#external-resources)
@@ -394,7 +394,8 @@ A timeout error **must** have its `type` set to `https://serverlessworkflow.io/s
394394
Serverless Workflow DSL is designed to seamlessly interact with a variety of services, ensuring robust service interoperability.
395395

396396
#### Supported Protocols
397-
- [**HTTP**](dsl-reference.md#http-call): Allows the workflow to make standard HTTP requests to web services. This is useful for RESTful services and web APIs that communicate over the HTTP protocol.
397+
398+
- [**HTTP**](dsl-reference.md#http-call): Allows the workflow to make standard HTTP requests to web services. This is useful for RESTful services and web APIs that communicate over the HTTP protocol.
398399
- [**gRPC**](dsl-reference.md#grpc-call): Supports Remote Procedure Call (RPC) using gRPC, a high-performance, open-source universal RPC framework. This is suitable for connecting to services that require low-latency and high-throughput communication.
399400
- [**AsyncAPI**](dsl-reference.md#asyncapi-call): Facilitates interaction with asynchronous messaging protocols. AsyncAPI is designed for event-driven architectures, allowing workflows to publish and subscribe to events.
400401
- [**OpenAPI**](dsl-reference.md#openapi-call): Enables communication with services that provide OpenAPI specifications, which is useful for defining and consuming RESTful APIs.
@@ -411,47 +412,54 @@ For custom interactions, the workflow can define [tasks](dsl-reference.md#run) t
411412

412413
Serverless Workflow DSL supports the creation and publication of custom functions to extend the DSL capabilities.
413414

414-
Custom functions allow you to define specific tasks and interactions that are not covered by the default supported protocols. Here’s how you can define and use custom functions within your workflows.
415+
Custom functions allow you to define specific tasks and interactions that are not covered by the default supported protocols.
416+
417+
Here’s how you can define and use custom functions within your workflows:
415418

416-
1. In your repository, create a new directory for your function, for example, `/.serverless-workflow/functions/my-custom-function.
419+
1. In your repository, create a new directory for your function, for example, `/serverless-workflow/functions/my-custom-function`. It is strongly recommended that custom function authors include the semantic version of the function in its path. For instance, you might structure the path as `/serverless-workflow/functions/my-custom-function/1.0.0` to reflect the function's version.
417420

418-
2. Create a `function.yaml` file containing the [function's definition](dsl-reference.md#task).
421+
2. Create a `function.yaml` file containing the [function's definition](dsl-reference.md#task). Ideally, the function should document both its input and output. This is important for documentation and validation purposes.
419422

420423
```yaml
421424
#function.yaml
422-
validateEmailAddress:
423-
describe:
424-
summary: Validate email addresses from input data
425-
input:
426-
schema:
425+
input:
426+
schema:
427+
document:
427428
type: object
429+
description: The function's input
428430
properties:
429431
emailAddress:
430432
type: string
431-
output:
432-
schema:
433+
description: The email address to validate.
434+
output:
435+
schema:
436+
document:
433437
type: object
438+
description: The function's output
434439
properties:
435440
isValid:
436441
type: boolean
437-
run:
438-
script:
439-
type: javascript
440-
source: |
441-
function validateEmail(email) {
442-
const re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
443-
return re.test(email);
444-
}
445-
const emailAddress = '${ .emailAddress }';
446-
return { isValid: validateEmail(emailAddress) };
447-
442+
description: A boolean indicating whether or not the email address is valid.
443+
run:
444+
script:
445+
language: javascript
446+
code: |
447+
function validateEmail(email) {
448+
const re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
449+
return re.test(email);
450+
}
451+
return { isValid: validateEmail(emailAddress) };
452+
arguments:
453+
emailAddress: ${ .emailAddress }
448454
```
449455

450456
3. Optionally, add all the local files your function might need into its directory.
451457

452458
4. Commit and push your function to your repository.
453459

454-
5. Optionally, submit your function to the Serverless Worfklow Function Registry, allowing users to find your function.
460+
5. Optionally, submit your function to the [Serverless Workflow Catalog](https://github.com/serverlessworkflow/catalog), allowing users to find your function.
461+
462+
For more information about authoring a new custom function, visit the [Serverless Workflow Catalog](https://github.com/serverlessworkflow/catalog).
455463

456464
##### Using a Custom Function
457465

@@ -466,20 +474,21 @@ document:
466474
namespace: default
467475
name: customFunctionWorkflow
468476
version: '0.1.0'
469-
470477
do:
471478
- validateEmail:
472-
call: https://github.com/myorg/functions/validateEmailAddress@v1
479+
call: https://github.com/myorg/functions/validateEmailAddress@v1.0.0
473480
with:
474481
emailAddress: ${ .userEmail }
475482
```
476483

477484
##### Publishing a Custom Function
478485

479-
Consider submitting your function to the Serverless Workflow Function Registry.
486+
Consider submitting your function to the [Serverless Workflow Function Catalog](https://github.com/serverlessworkflow/catalog).
480487

481488
This optional step allows users to discover and utilize your function, enhancing its visibility and usability within the Serverless Workflow community. By registering your function, you contribute to a shared repository of resources that can streamline workflow development for others.
482489

490+
For detailed instructions on how to contribute your custom function, please refer to the [CONTRIBUTING.md](https://github.com/serverlessworkflow/catalog/blob/main/CONTRIBUTING.md) file.
491+
483492
### Events
484493

485494
Events play a crucial role in Serverless Workflow by facilitating communication and coordination between different components and services. They enable workflows to react to external stimuli, paving the way for event-driven architectures and real-time processing scenarios. Events are essentially messages that convey information about a specific occurrence or action, allowing workflows to respond dynamically to changes in their environment.

0 commit comments

Comments
 (0)