| 3521 | } |
| 3522 | |
| 3523 | func TestResolverCompositionCalledOnce(t *testing.T) { |
| 3524 | r, app := humatest.New(t, huma.DefaultConfig("Test API", "1.0.0")) |
| 3525 | huma.Register(app, huma.Operation{ |
| 3526 | OperationID: "test", |
| 3527 | Method: http.MethodPut, |
| 3528 | Path: "/test", |
| 3529 | }, func(ctx context.Context, input *struct { |
| 3530 | ResolverCalls |
| 3531 | }) (*struct{}, error) { |
| 3532 | // Exactly one call should have been made to the resolver. |
| 3533 | assert.Equal(t, 1, input.Calls) |
| 3534 | return nil, nil |
| 3535 | }) |
| 3536 | |
| 3537 | req, _ := http.NewRequest(http.MethodPut, "/test", strings.NewReader(`{}`)) |
| 3538 | req.Header.Set("Content-Type", "application/json") |
| 3539 | w := httptest.NewRecorder() |
| 3540 | r.ServeHTTP(w, req) |
| 3541 | assert.Equal(t, http.StatusNoContent, w.Code, w.Body.String()) |
| 3542 | } |
| 3543 | |
| 3544 | type ResolverWithPointer struct { |
| 3545 | Ptr *string |