generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for HttpRequest[[]byte] (#860)
- Loading branch information
1 parent
79a078b
commit 485e256
Showing
11 changed files
with
255 additions
and
317 deletions.
There are no files selected for viewing
This file contains 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 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,57 @@ | ||
package ingress | ||
|
||
import ( | ||
"github.com/TBD54566975/ftl/backend/schema" | ||
) | ||
|
||
func transformFromAliasedFields(dataRef *schema.DataRef, sch *schema.Schema, request map[string]any) (map[string]any, error) { | ||
data, err := sch.ResolveDataRefMonomorphised(dataRef) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, field := range data.Fields { | ||
if _, ok := request[field.Name]; !ok && field.Alias != "" && request[field.Alias] != nil { | ||
request[field.Name] = request[field.Alias] | ||
delete(request, field.Alias) | ||
} | ||
|
||
if d, ok := field.Type.(*schema.DataRef); ok { | ||
if _, found := request[field.Name]; found { | ||
rMap, err := transformFromAliasedFields(d, sch, request[field.Name].(map[string]any)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
request[field.Name] = rMap | ||
} | ||
} | ||
} | ||
|
||
return request, nil | ||
} | ||
|
||
func transformToAliasedFields(dataRef *schema.DataRef, sch *schema.Schema, request map[string]any) (map[string]any, error) { | ||
data, err := sch.ResolveDataRefMonomorphised(dataRef) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, field := range data.Fields { | ||
if field.Alias != "" && field.Name != field.Alias { | ||
request[field.Alias] = request[field.Name] | ||
delete(request, field.Name) | ||
} | ||
|
||
if d, ok := field.Type.(*schema.DataRef); ok { | ||
if _, found := request[field.Name]; found { | ||
rMap, err := transformToAliasedFields(d, sch, request[field.Name].(map[string]any)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
request[field.Name] = rMap | ||
} | ||
} | ||
} | ||
|
||
return request, nil | ||
} |
This file contains 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 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
Oops, something went wrong.