| 3552 | } |
| 3553 | |
| 3554 | func TestResolverWithPointer(t *testing.T) { |
| 3555 | // Allow using pointers in input structs if they are not path/query/header/cookie parameters |
| 3556 | r, app := humatest.New(t, huma.DefaultConfig("Test API", "1.0.0")) |
| 3557 | huma.Register(app, huma.Operation{ |
| 3558 | OperationID: "test", |
| 3559 | Method: http.MethodPut, |
| 3560 | Path: "/test", |
| 3561 | }, func(ctx context.Context, input *struct { |
| 3562 | ResolverWithPointer |
| 3563 | }) (*struct{}, error) { |
| 3564 | // Exactly one call should have been made to the resolver. |
| 3565 | assert.Equal(t, "String", *input.Ptr) |
| 3566 | return nil, nil |
| 3567 | }) |
| 3568 | |
| 3569 | req, _ := http.NewRequest(http.MethodPut, "/test", strings.NewReader(`{}`)) |
| 3570 | req.Header.Set("Content-Type", "application/json") |
| 3571 | w := httptest.NewRecorder() |
| 3572 | r.ServeHTTP(w, req) |
| 3573 | assert.Equal(t, http.StatusNoContent, w.Code, w.Body.String()) |
| 3574 | } |
| 3575 | |
| 3576 | func TestParamPointerPanics(t *testing.T) { |
| 3577 | // For now, we don't support these, so we panic rather than have subtle |