From c2bc2c7e4a18a5ca5b3a4c6111f558c7127a313b Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Fri, 10 Feb 2023 17:21:49 +1100 Subject: [PATCH] functionbuilder --- build/app/models/post_params_body.go | 3 --- build/app/restapi/embedded_spec.go | 20 ++++++-------------- readme.md | 14 ++++++++------ tests/v1.0/tests.yaml | 4 +++- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/build/app/models/post_params_body.go b/build/app/models/post_params_body.go index c9ef761..c62d5d3 100644 --- a/build/app/models/post_params_body.go +++ b/build/app/models/post_params_body.go @@ -24,9 +24,6 @@ type PostParamsBody struct { // File to create before running commands. Files []apps.DirektivFile `json:"files"` - // json input to convert to spreadsheet - InData interface{} `json:"in-data,omitempty"` - // Name of the json input file to utilise Infile string `json:"infile,omitempty"` diff --git a/build/app/restapi/embedded_spec.go b/build/app/restapi/embedded_spec.go index 4634098..318b6a6 100644 --- a/build/app/restapi/embedded_spec.go +++ b/build/app/restapi/embedded_spec.go @@ -80,10 +80,6 @@ func init() { "$ref": "#/definitions/direktivFile" } }, - "in-data": { - "description": "json input to convert to spreadsheet", - "type": "object" - }, "infile": { "description": "Name of the json input file to utilise", "type": "string" @@ -156,11 +152,11 @@ func init() { "x-direktiv-examples": [ { "content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n files:\n - name: input.json\n data: |\n jq(.input) \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx", - "title": "Rely on Direktiv to create input file" + "title": "Basic" }, { - "content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx\n in-data: jq(.array | tostring) ", - "title": "Use function to create input file" + "content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n files:\n - name: input.json\n data: |\n jq(.array | {input: . } | tostring ) \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx ", + "title": "Use jq to add a parent key 'input' containing array of objects" } ], "x-direktiv-function": "functions:\n- id: export-xlsx\n image: registry.coadcorp.com/export-xlsx:1.0\n type: knative-workflow", @@ -319,11 +315,11 @@ func init() { "x-direktiv-examples": [ { "content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n files:\n - name: input.json\n data: |\n jq(.input) \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx", - "title": "Rely on Direktiv to create input file" + "title": "Basic" }, { - "content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx\n in-data: jq(.array | tostring) ", - "title": "Use function to create input file" + "content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n files:\n - name: input.json\n data: |\n jq(.array | {input: . } | tostring ) \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx ", + "title": "Use jq to add a parent key 'input' containing array of objects" } ], "x-direktiv-function": "functions:\n- id: export-xlsx\n image: registry.coadcorp.com/export-xlsx:1.0\n type: knative-workflow", @@ -404,10 +400,6 @@ func init() { "$ref": "#/definitions/direktivFile" } }, - "in-data": { - "description": "json input to convert to spreadsheet", - "type": "object" - }, "infile": { "description": "Name of the json input file to utilise", "type": "string" diff --git a/readme.md b/readme.md index 0d42298..db0c073 100644 --- a/readme.md +++ b/readme.md @@ -24,7 +24,7 @@ functions: image: registry.coadcorp.com/export-xlsx:1.0 type: knative-workflow ``` - #### Rely on Direktiv to create input file + #### Basic ```yaml - id: export-xlsx type: action @@ -38,16 +38,19 @@ functions: worksheet-name: "TestSpreadsheet" out-filename: example.xlsx ``` - #### Use function to create input file + #### Use jq to add a parent key 'input' containing array of objects ```yaml - id: export-xlsx type: action action: function: export-xlsx - input: + input: + files: + - name: input.json + data: | + jq(.array | {input: . } | tostring ) worksheet-name: "TestSpreadsheet" - out-filename: example.xlsx - in-data: jq(.array | tostring) + out-filename: example.xlsx ``` ### Secrets @@ -113,7 +116,6 @@ functions: | Name | Type | Go type | Required | Default | Description | Example | |------|------|---------|:--------:| ------- |-------------|---------| | files | [][DirektivFile](#direktiv-file)| `[]apps.DirektivFile` | | | File to create before running commands. | | -| in-data | [interface{}](#interface)| `interface{}` | | | json input to convert to spreadsheet | | | infile | string| `string` | | | Name of the json input file to utilise | | | out-filename | string| `string` | ✓ | `"output.xlsx"`| the filename of the output spreadsheet | | | worksheet-name | string| `string` | ✓ | `"Sheet1"`| Label for the worksheet created in the spreadsheet | | diff --git a/tests/v1.0/tests.yaml b/tests/v1.0/tests.yaml index a232b76..f10479e 100644 --- a/tests/v1.0/tests.yaml +++ b/tests/v1.0/tests.yaml @@ -20,6 +20,8 @@ states: action: function: export-xlsx input: - in-data: jq(.array | tostring) + files: + - data: "jq(.array | {input: . } | tostring ) \n" + name: input.json out-filename: example.xlsx worksheet-name: TestSpreadsheet