-
Notifications
You must be signed in to change notification settings - Fork 166
Adds support for external resources #701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
cdavernas
wants to merge
7
commits into
serverlessworkflow:main
from
neuroglia-io:external-resources
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
68a272a
Added the resources.json schema
cdavernas aa65b41
Fixed Workflow Definition Structure property descriptions to match th…
cdavernas 69fa217
Added example and updated roadmap
cdavernas d2e864c
Updated roadmap
cdavernas c6aa5dd
Merge branch 'main' into external-resources
cdavernas 8ccce76
Merge branch 'main' into external-resources
cdavernas 7a4fe8a
Update examples/README.md
cdavernas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ Provides Serverless Workflow language examples | |
| - [Online Food Ordering](#Online-Food-Ordering) | ||
| - [Continuing as a new Execution](#Continuing-as-a-new-Execution) | ||
| - [Process Transactions (Foreach State with conditions)](#Process-Transactions) | ||
| - [Import external resources](#import-external-resources) | ||
|
|
||
| ### Hello World Example | ||
|
|
||
|
|
@@ -4944,3 +4945,141 @@ functions: | |
| </td> | ||
| </tr> | ||
| </table> | ||
|
|
||
| ### Import External Resources | ||
|
|
||
| #### Description | ||
|
|
||
| For the example, let's assume we have developed a number of workflows to orchestrate an hypothetical, event-driven management solution around the Swagger Pet Store API. | ||
|
|
||
| At start, we were copy/pasting the many Pet Store function definitions from workflow to workflow as we needed them. Even though that was very tedious, we just coped with it, until that day where the names of a couple of functions changed in the `swagger.json`, breaking most of our workflows. | ||
|
|
||
| We then sat down, and agreed for our sanity to respect the DRY principle, and only declare those functions once, in an hypothetical `https://fake.examples/sw/petstore.yaml` file, that could look like the following: | ||
|
|
||
| ```yaml | ||
| functions: | ||
| - name: add-pet | ||
| type: openapi | ||
| operation: https://petstore.swagger.io/v2/swagger.json#addPet | ||
| - name: get-pet-by-id | ||
| type: openapi | ||
| operation: https://petstore.swagger.io/v2/swagger.json#getPetById | ||
| - name: update-pet | ||
| type: openapi | ||
| operation: https://petstore.swagger.io/v2/swagger.json#updatePet | ||
| - name: delete-pet | ||
| type: openapi | ||
| operation: https://petstore.swagger.io/v2/swagger.json#deletePet | ||
| ``` | ||
|
|
||
| Starting from there, we could now reuse those definitions in any workflows by just importing them: | ||
|
|
||
| #### Workflow Definition | ||
|
|
||
| <table> | ||
| <tr> | ||
| <th>JSON</th> | ||
| <th>YAML</th> | ||
| </tr> | ||
| <tr> | ||
| <td valign="top"> | ||
|
|
||
| ```json | ||
| { | ||
| "id": "get-pet-availability", | ||
| "name": "Get Pet Availability", | ||
| "version": "1.0.0", | ||
| "specVersion": 0.8, | ||
| "resources": [ | ||
| { | ||
| "name": "petstore", | ||
| "uri": "https://test.com/myresource.json" | ||
| } | ||
| ], | ||
| "functions": [ | ||
| { | ||
| "name": "email-send", | ||
| "type": "openapi", | ||
| "operation": "smtp.json#send" | ||
| } | ||
| ], | ||
| "states": [ | ||
| { | ||
| "name": "get-pet", | ||
| "type": "operation", | ||
| "actions": [ | ||
| { | ||
| "name": "get-pet-by-id", | ||
| "functionRef": { | ||
| "refName": "petstore.get-pet-by-id", | ||
| "arguments": { | ||
| "petId": "${ .input.petId }" | ||
| } | ||
| }, | ||
| "actionDataFilter": { | ||
| "toStateData": "${ .pet }" | ||
| } | ||
| }, | ||
| { | ||
| "name": "send-pet-status-by-email", | ||
| "functionRef": { | ||
| "refName": "email-send", | ||
| "arguments": { | ||
| "from": "[email protected]", | ||
| "to": "${ .input.client.email }", | ||
| "subject": "Pet Inquiry Result", | ||
| "isBodyHtml": true, | ||
| "body": "The status of the pet you enquired (${ .input.petId }) about is '${ .pet.status }'" | ||
| } | ||
| } | ||
| } | ||
| ], | ||
| "end": true | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| </td> | ||
| <td valign="top"> | ||
|
|
||
| ```yaml | ||
| id: get-pet-availability | ||
| name: Get Pet Availability | ||
| version: 1.0.0 | ||
| specVersion: 0.8 | ||
| resources: | ||
| - name: petstore | ||
| uri: 'https://test.com/myresource.json' | ||
| functions: | ||
| - name: email-send | ||
| type: openapi | ||
| operation: 'smtp.json#send' | ||
| states: | ||
| - name: get-pet | ||
| type: operation | ||
| actions: | ||
| - name: get-pet-by-id | ||
| functionRef: | ||
| refName: petstore.get-pet-by-id | ||
| arguments: | ||
| petId: '${ .input.petId }' | ||
| actionDataFilter: | ||
| toStateData: '${ .pet }' | ||
| - name: send-pet-status-by-email | ||
| functionRef: | ||
| refName: email-send | ||
| arguments: | ||
| from: [email protected] | ||
| to: '${ .input.client.email }' | ||
| subject: Pet Inquiry Result | ||
| isBodyHtml: true | ||
| body: >- | ||
| The status of the pet you enquired (${ .input.petId }) about is | ||
| '${ .pet.status }' | ||
| end: true | ||
| ``` | ||
|
|
||
| </td> | ||
| </tr> | ||
| </table> | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,100 @@ | ||
| { | ||
| "$id": "https://serverlessworkflow.io/schemas/0.8/resources.json", | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "description": "Serverless Workflow specification - resources schema", | ||
| "type": "object", | ||
| "resources":{ | ||
| "type": "array", | ||
| "description": "Defines the external resources referenced by the workflow", | ||
| "items": { | ||
| "type": "object", | ||
| "$ref": "#/definitions/resourceRef" | ||
| }, | ||
| "additionalItems": false, | ||
| "minItems": 1 | ||
| }, | ||
| "required":[ | ||
| "resources" | ||
| ], | ||
| "definitions":{ | ||
| "resourceRef":{ | ||
| "type": "object", | ||
| "description": "References an external resource", | ||
| "properties": { | ||
| "name": { | ||
| "type": "string", | ||
| "description": "The name of the external resource. It must be lowercased and must only contain alphanumeric characters, with the exception of `-` and `_`. The name is used as prefix to reference any definition contained in the referenced resource.", | ||
| "pattern": "^[a-z0-9-_]+$" | ||
| }, | ||
| "uri": { | ||
| "type": "string", | ||
| "format": "uri", | ||
| "description": "The uri at which to find the referenced external resource definition" | ||
| }, | ||
| "authRef": { | ||
| "type": "string", | ||
| "description": "References the (inline) auth definition used to retrieve the referenced external resource" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "name", | ||
| "uri" | ||
| ] | ||
| }, | ||
| "resourceDef":{ | ||
cdavernas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "type": "object", | ||
| "description": "Defines an external resource", | ||
| "properties": { | ||
| "constants": { | ||
| "type": "object" | ||
| }, | ||
| "secrets": { | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "secrets.json#/secrets" | ||
| } | ||
| }, | ||
| "retries": { | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "retries.json#/retries" | ||
| } | ||
| }, | ||
| "auth": { | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "auth.json#/auth" | ||
| } | ||
| }, | ||
| "timeouts": { | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "timeouts.json#/timeouts" | ||
| } | ||
| }, | ||
| "events": { | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "events.json#/events" | ||
| } | ||
| }, | ||
| "functions": { | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "functions.json#/functions" | ||
| } | ||
| }, | ||
| "errors": { | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "errors.json#/errors" | ||
| } | ||
| }, | ||
| "metadata":{ | ||
cdavernas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "type": "object", | ||
| "additionalProperties": true | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.