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

Update mangleQueryParameters to convert to underlying schema type instead of always strings #3037

Closed
wesbillman opened this issue Oct 8, 2024 · 0 comments · Fixed by #3049
Labels
dx next Work that will be be picked up next

Comments

@wesbillman
Copy link
Collaborator

Using a non-string type (like int) in a query param struct will cause an encoding failure and internal server error. For example, it would be nice if we could support an http ingress like this:

type GetQueryParams struct {
	Age ftl.Option[int] `json:"age"`
}

type GetPathParams struct {
	Name string `json:"name"`
}

type GetResponse struct {
	Name string          `json:"name"`
	Age  ftl.Option[int] `json:"age"`
}

// Example usage of path and query params
// curl http://localhost:8891/get/wicket?age=10
//
//ftl:ingress http GET /get/{name}
func Get(ctx context.Context, req builtin.HttpRequest[ftl.Unit, GetPathParams, GetQueryParams]) (builtin.HttpResponse[GetResponse, ApiError], error) {
	return builtin.HttpResponse[GetResponse, ApiError]{
		Status: 200,
		Body: ftl.Some(GetResponse{
			Name: req.PathParameters.Name,
			Age:  req.Query.Age,
		}),
	}, nil
}

This will currently fail with:

error:http:runner0: Call to deployments dpl-http-e12hoaj2xyu13r5 failed: invalid request to verb http.get: json: cannot unmarshal string into Go value of type int
@wesbillman wesbillman added the dx label Oct 8, 2024
@github-actions github-actions bot added the triage Issue needs triaging label Oct 8, 2024
This was referenced Oct 8, 2024
@stuartwdouglas stuartwdouglas added next Work that will be be picked up next and removed triage Issue needs triaging labels Oct 8, 2024
stuartwdouglas added a commit that referenced this issue Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dx next Work that will be be picked up next
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants