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

encoding removes empty slices which makes returning empty arrays from ingress fail #1151

Closed
wesbillman opened this issue Mar 29, 2024 · 0 comments
Assignees

Comments

@wesbillman
Copy link
Collaborator

If a project has an http ingress with a response spec that might return something like this

{
  "data": []
}

Where the API specifies it will return an empty array, we currently strip the "data" field from the json response because of our encoding.

type GoodResponse struct {
	Data []string `json:"data"`
}

//ftl:export
//ftl:ingress GET /good
func Good(ctx context.Context, req builtin.HttpRequest[GoodRequest]) (builtin.HttpResponse[GoodResponse, builtin.Empty], error) {
	resp := GoodResponse{Data: []string{}}
	return builtin.HttpResponse[GoodResponse, builtin.Empty]{
		Body:   ftl.Some(resp),
	}, nil
}

The code above will return {} where the user and API wants {"data":[]}.

This seems to be happening here https://github.com/TBD54566975/ftl/blob/main/go-runtime/encoding/encoding.go#L119-L125.

Should we add some logic to honor omitempty for fields like this? Or remove the stripping of empty fields here? Or is there a better option for users?

Currently, the work around is to use a response type of []byte and handle the json encoding manually in the user code.

cc: @mistermoe

@github-actions github-actions bot added the triage Issue needs triaging label Mar 29, 2024
@alecthomas alecthomas self-assigned this Apr 8, 2024
@github-actions github-actions bot removed the triage Issue needs triaging label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants