Skip to content

Commit fb7f1ff

Browse files
committed
Made reverse translation with custom_action work well (AKA HTTP is VERY auto-correctable)
1 parent d50c8d3 commit fb7f1ff

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.24.0
44

55
toolchain go1.24.4
66

7-
//replace github.com/frikky/schemaless => ../schemaless
7+
replace github.com/frikky/schemaless => ../schemaless
88
replace github.com/shuffle/shuffle-shared => ../shuffle-shared
99

1010
require (

pkg/api.go

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,8 @@ func RunActionWrapper(ctx context.Context, user shuffle.User, value shuffle.Cate
11631163
fieldFileContentMap := map[string]interface{}{}
11641164

11651165
discoverFile := ""
1166+
1167+
// Replaces translation_output & app_defaults -> real input values
11661168
if len(value.Fields) > 0 {
11671169
sortedKeys := []string{}
11681170
for _, field := range value.Fields {
@@ -1771,7 +1773,7 @@ func RunActionWrapper(ctx context.Context, user shuffle.User, value shuffle.Cate
17711773
secondAction.AppName = selectedApp.Name
17721774
}
17731775

1774-
selectedAction = GetOrgspecificParameters(ctx, *org, selectedAction)
1776+
selectedAction = GetOrgspecificParameters(ctx, value.Fields, *org, selectedAction)
17751777

17761778
//log.Printf("[DEBUG] Required bodyfields: %#v", selectedAction.RequiredBodyFields)
17771779
handledRequiredFields := []string{}
@@ -2031,7 +2033,7 @@ func RunActionWrapper(ctx context.Context, user shuffle.User, value shuffle.Cate
20312033
authorization := ""
20322034
optionalExecutionId := ""
20332035
client := shuffle.GetExternalClient(baseUrl)
2034-
if len(missingFields) > 0 {
2036+
if len(missingFields) > 0 && selectedAction.Name != "custom_action" {
20352037
if debug {
20362038
log.Printf("[DEBUG] Missing fields for action: %#v. This means the current translation may be missing or wrong. Setting fieldFileFound back to false and re-setting it at the end", missingFields)
20372039
}
@@ -2143,7 +2145,7 @@ func RunActionWrapper(ctx context.Context, user shuffle.User, value shuffle.Cate
21432145
// Runs individual apps, one at a time
21442146
if value.SkipWorkflow {
21452147

2146-
if len(missingFields) > 0 {
2148+
if len(missingFields) > 0 && selectedAction.Name != "custom_action" {
21472149
log.Printf("[WARNING] Not all required fields were found in category action (2). Want: %#v in action %s", missingFields, selectedAction.Name)
21482150
//respBody = []byte(fmt.Sprintf(`{"success": false, "reason": "Not all required fields are set", "label": "%s", "missing_fields": "%s", "action": "%s", "api_debugger_url": "%s"}`, value.Label, strings.Join(missingFields, ","), selectedAction.Name, fmt.Sprintf("https://shuffler.io/apis/%s", selectedApp.ID)))
21492151
//resp.WriteHeader(400)
@@ -2282,9 +2284,6 @@ func RunActionWrapper(ctx context.Context, user shuffle.User, value shuffle.Cate
22822284
log.Printf("[ERROR] Failed marshalling prepared body for execute generated app run (1): %s", err)
22832285
}
22842286
}
2285-
2286-
log.Printf("NEW APPRUN BODY:\n%s", string(apprunBody))
2287-
22882287
}
22892288

22902289
// Standalone => runs the app, but as a "subflow", which locally
@@ -2519,9 +2518,9 @@ func RunActionWrapper(ctx context.Context, user shuffle.User, value shuffle.Cate
25192518
*/
25202519

25212520
if standalone {
2522-
shuffle.UploadParameterBase(context.Background(), user.ActiveOrg.Id, selectedApp.ID, secondAction.Name, param.Name, param.Value)
2521+
shuffle.UploadParameterBase(context.Background(), value.Fields, user.ActiveOrg.Id, selectedApp.ID, secondAction.Name, param.Name, param.Value)
25232522
} else {
2524-
go shuffle.UploadParameterBase(context.Background(), user.ActiveOrg.Id, selectedApp.ID, secondAction.Name, param.Name, param.Value)
2523+
go shuffle.UploadParameterBase(context.Background(), value.Fields, user.ActiveOrg.Id, selectedApp.ID, secondAction.Name, param.Name, param.Value)
25252524
}
25262525
}
25272526

@@ -2702,7 +2701,10 @@ func RunActionWrapper(ctx context.Context, user shuffle.User, value shuffle.Cate
27022701
log.Printf("[WARNING] Failed unmarshalling schemaless (2) output for label %s: %s", value.Label, err)
27032702
}
27042703
} else {
2705-
parsedTranslation.Output = outputmap
2704+
if len(outputmap) > 0 {
2705+
parsedTranslation.Output = outputmap
2706+
}
2707+
27062708
//parsedTranslation.RawResponse = nil
27072709
}
27082710

@@ -3413,15 +3415,19 @@ func StoreTranslationOutput(user shuffle.User, fieldHash string, parsedParameter
34133415
if err != nil {
34143416
log.Printf("[ERROR] Problem with schemaless reversing: %s", err)
34153417
} else {
3416-
log.Printf("[DEBUG] Raw schemaless reverse: %s", reversed)
3418+
if debug {
3419+
log.Printf("[DEBUG] Raw schemaless reverse: %s", reversed)
3420+
}
34173421

34183422
finishedFields := 0
34193423
mappedFields := map[string]interface{}{}
34203424
err = json.Unmarshal([]byte(reversed), &mappedFields)
34213425
if err == nil {
34223426
for _, value := range mappedFields {
3423-
if _, ok := value.(string); ok && len(value.(string)) > 0 {
3424-
finishedFields++
3427+
if _, ok := value.(string); ok {
3428+
if len(value.(string)) > 0 {
3429+
finishedFields++
3430+
}
34253431
} else {
34263432
log.Printf("[DEBUG] Found non-string value: %#v", value)
34273433
}
@@ -3463,7 +3469,9 @@ func StoreTranslationOutput(user shuffle.User, fieldHash string, parsedParameter
34633469
if err != nil {
34643470
log.Printf("[ERROR] Problem uploading file: %s", err)
34653471
} else {
3466-
log.Printf("[DEBUG] Uploaded file with ID: %s", returnedId)
3472+
if debug {
3473+
log.Printf("[DEBUG] Uploaded file with ID: %s", returnedId)
3474+
}
34673475
}
34683476
}
34693477
}
@@ -3894,7 +3902,7 @@ func handleStandaloneExecution(workflow shuffle.Workflow) ([]byte, error) {
38943902
return []byte(output), nil
38953903
}
38963904

3897-
func GetOrgspecificParameters(ctx context.Context, org shuffle.Org, action shuffle.WorkflowAppAction) shuffle.WorkflowAppAction {
3905+
func GetOrgspecificParameters(ctx context.Context, fields []shuffle.Valuereplace, org shuffle.Org, action shuffle.WorkflowAppAction) shuffle.WorkflowAppAction {
38983906
//log.Printf("\n\n[DEBUG] LOADING ORG SPECIFIC PARAMETERS\n\n")
38993907
for paramIndex, param := range action.Parameters {
39003908
if param.Configuration && param.Name != "url" {
@@ -3936,8 +3944,13 @@ func GetOrgspecificParameters(ctx context.Context, org shuffle.Org, action shuff
39363944
continue
39373945
}
39383946

3939-
action.Parameters[paramIndex].Value = string(content)
3940-
action.Parameters[paramIndex].Example = string(content)
3947+
stringContent := string(content)
3948+
for _, field := range fields {
3949+
stringContent = strings.ReplaceAll(stringContent, fmt.Sprintf("{%s}", field.Key), field.Value)
3950+
}
3951+
3952+
action.Parameters[paramIndex].Value = stringContent
3953+
action.Parameters[paramIndex].Example = stringContent
39413954
}
39423955

39433956
return action

0 commit comments

Comments
 (0)