Skip to content
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

Com.gs.return fix #980

Closed
2 tasks done
mastersilv3r opened this issue Feb 27, 2024 · 0 comments · Fixed by #989 or #992
Closed
2 tasks done

Com.gs.return fix #980

mastersilv3r opened this issue Feb 27, 2024 · 0 comments · Fixed by #989 or #992
Labels
feature new feature

Comments

@mastersilv3r
Copy link
Contributor

mastersilv3r commented Feb 27, 2024

The Problem

Need similar behavior of com.gs.return and com.gs.transform inbuilt workflows

Both com.gs.return and com.gs.transform should behave in the same way(as per below specifications) except that com.gs.return will do the transformation and exit the workflow however com.gs.transform will just do the transformation of result.

The GSStatus is a built-in class in Godspeed. All functions in the framework or written by developer, whether tasks in yaml or typescript funtions or workflows in yaml, have to return either GSStatus or data.
The GSStatus has five keys: code , success, message , data , headers

  • Now lets see how the framework will qualify your return as GSStatus or simple data.
    The framework will see that your returned data has one of code or success meta-keys. if present, it will look for the other GSStatus keys defined above and set them. If it doesn't find any of these keys, it will assume all that you have returned is intended to be GSStatus.data.
    It will add code: 200 and success: true internally to your response and create a GSStatus out of it to pass on to next tasks or workflows.

Example 1

tasks:
  - id: first_task
    fn: com.gs.return
    args: 
       code: 400
       success: false
       data: "Invalid input error"
       key1: "E001"
       key2: "E002"
       headers: 
          title: "MS1"

this should return

code: 400
success: false
data: "Invalid input error"
headers: 
   "title": "MS1"

Example 2

tasks:
  - id: first_task
    fn: com.gs.return
    args: <% "Hello World. This is " + inputs.query.name_one + " ."%>

this should return

code: 200
success:true
data: 'Hello world. This is name_from_query.

Example 3

tasks:
  - id: first_task
    fn: com.gs.return
    args: 
       key1: "E001"
       key2: "E002"

This should return

code: 200
success: true
data: 
       "key1": "E001"
       "key2": "E002"
  • Deprecated: If the developer uses a flag called defaults.returnV1Compatible in config/default.yaml then the code, success and message of args is not copied to the finally returned GSStatus. The data of returned GSSTatus contains entire args object, with code, message, data, success. Its own code is 200 and success is true always. The same two examples above would return

Setting in default.yaml

defaults:
   returnV1Compatible: true # com.gs.return should behave in V1 compatible way

Example 1

tasks:
  - id: first_task
    fn: com.gs.return
    args: <% "Hello World. This is " + inputs.query.name_one + " ."%>

this should return

code: 200
success:true
data: 'Hello world. This is name_from_query.

Example 2

tasks:
  - id: first_task
    fn: com.gs.return
    args: 
       code: 400
       success: false
       data: "Invalid input error"

this should return

code: 200
success: true
data:
   code: 400
   success: false
   data: Invalid input error

The Solution

Fix com.gs.return behavior in core/functions

How to test

With config/default.yaml has defaults.returnV1Compatible to false or undefined

Example 1

tasks:
  - id: first_task
    fn: com.gs.return
    args: 
       code: 400
       success: false
       data: "Invalid input error"
       key1: "E001"
       key2: "E002"
       headers: 
          title: "MS1"

this should return

code: 400
success: false
data: "Invalid input error"
headers: 
   "title": "MS1"

Example 2

tasks:
  - id: first_task
    fn: com.gs.return
    args: <% "Hello World. This is " + inputs.query.name_one + " ."%>

this should return

code: 200
success:true
data: 'Hello world. This is name_from_query.

Example 3

tasks:
  - id: first_task
    fn: com.gs.return
    args: 
       key1: "E001"
       key2: "E002"

This should return

code: 200
success: true
data: 
       "key1": "E001"
       "key2": "E002"

Example 4

tasks:
  - id: first_task
    fn: com.gs.return
    args: true

This should return

code: 200
success: true
data: true

With config/default.yaml has defaults.returnV1Compatible to true

Example 1

tasks:
  - id: first_task
    fn: com.gs.return
    args: <% "Hello World. This is " + inputs.query.name_one + " ."%>

this should return

code: 200
success:true
data: 'Hello world. This is name_from_query.

Example 2

tasks:
  - id: first_task
    fn: com.gs.return
    args: 
       code: 400
       success: false
       data: "Invalid input error"

this should return

code: 200
success: true
data:
   code: 400
   success: false
   data: Invalid input error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature new feature
Projects
None yet
2 participants